package com.rytong.tools.ui;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.security.cert.Certificate;
import java.security.interfaces.RSAPublicKey;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import org.keplerproject.luajava.LuaException;
import org.keplerproject.luajava.LuaObject;
import org.keplerproject.luajava.LuaState;
import org.xml.sax.SAXException;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.text.TextPaint;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewParent;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.AbsoluteLayout;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.ScrollView;
import android.widget.TextView;
import com.rytong.tools.animation.EmpAnimation;
import com.rytong.tools.clienthello.ClientHello;
import com.rytong.tools.crypto.AESCipher;
import com.rytong.tools.crypto.Base64;
import com.rytong.tools.crypto.Constant;
import com.rytong.tools.crypto.HMac;
import com.rytong.tools.crypto.RSACipher;
import com.rytong.tools.httpconnect.HttpManager;
import com.rytong.tools.httpconnect.HttpManager.NoGatewayException;
import com.rytong.tools.httpconnect.WaitDialog;
import com.rytong.tools.httpconnect.WaitDialog.Task;
import com.rytong.tools.ui.LPCheckBox.MyLPCheckBox;
import com.rytong.tools.ui.LPLayout.HSView;
import com.rytong.tools.ui.LPLayout.MyLPLayout;
import com.rytong.tools.ui.LPRadio.MyLPRadio;
import com.rytong.tools.utils.LPToastUtil;
import com.rytong.tools.utils.Utils;

/**
 * 
 * @author wudong
 */
public abstract class Component {
    // 控件剩余的宽度,主要用于框架类控件布局子元素的自动换行效果
    // int wRest_;
    // 控件上下留白高度
    int blankY_ = 2;
    int coordinate_x = 0;
    int SPACE_Y_ = 6;// 行间距
    // 这个变量里面存放的是分好段的文字数组。
    public String[] stringArr_;
    // 字符坐标数组。
    public float[][] pos_ = null;
    // 控件前面br节点的高度，如果前面是单个br节点，则无高度处理，只是换行，仅当存在连续多个br节点时该属性才有具体参考值
    protected int brHeight_;
    protected int acquiescentHeight_;
    protected int acquiescentWidth_;
    public static int SCREENWIDTH = 0;
    public static int SCREENHEIGHT = 0;
    public static LayoutParams prms = new android.widget.AbsoluteLayout.LayoutParams(320, 480, 0, 0);
    // 移动字符串起始递减值
    private int start_;
    // 进度提示警告辨识标志
    public final static String PROGRESSDIALOG = "ProgressDialog";
    /**
     *  llv层的top高度
     */
    protected int llvTop_;
    // 标志翻页功能是否正在执行
    protected boolean throwPageIsWork_;
    // 控件自身相对于父控件的布局值
    int xParentMax_;
    int yParentMax_;
    int yParentTop_;
    int wParentMax_;
    int hParentMax_;
    /**
     * 记录布局控件y方向最大值，方便控件排列，看来随着子控件的增加，这个值会逐渐变大（表示纵向高度逐渐变大）。
     */
    int ySelfMax_;
    /**
     * 记录布局控件x方向最大值，方便控件排列，看来随着子控件的增加，这个值会逐渐变大（表示横向宽度逐渐变大）。
     */
    int xSelfMax_;
    // 当管理器内控件多层排列时，该值记录控件n-1层的y值
    int ySelfTop_;
    /**
     * 分别记录控件自身的宽高最大值
     */
    protected int wSelfMax_;
    /**
     * 控件自身高度最大值。
     */
    protected int hSelfMax_;
    // 用户前一次点击的时间,主要用于判断是否连续点击
    public static long LASTCLICKTIME;
    // 时差值，该时差值从Config文件里面读取，用于判断是否为连击
    public int jetLag_;

    // 控件的XY记录值,由于控件绘制方法会重复计算,影响控件的布局,此两值记录控件的布局最终值
    public int left_;
    public int top_;

    public static final String RSACipherServerCerfile_ = "rootCA/A1Cert.crt";
    public static Certificate RSACipherServerCer_;
    // 项目新加密码临时变量，保证一个form只用一次key和iv
    public static byte[] KEYTEMP;
    public static byte[] IVTEMP;
    // 弹出框哈希，记录界面里所有弹出的弹出框
    public static HashMap DIALOGHASH;
    // 控件的子元素集合,例如select控件,option就是她的子元素,该集合专门存储这类子元素
    public ArrayList<Component> childrenList_;
    // 界面栈,存储界面报文
    public static Stack ACTIONV;
    public static LuaState LUASTATE;
    public static boolean isShowLoading = false;

    /**
     * 标志控件前面是否是br节点,如果是则需另起一行布局
     */
    public boolean isAfterBr_;
    /**
     * 是否是html中的块级元素标志，如div 、form、table等，块级元素前后需要换行，除非样式中指定display：inline才不做换行处理
     */
    public boolean isNewLine_;
    // 控件画笔对象
    public Paint paint_;
    // 控件属性集合(自定义需要保存的属性)
    public HashMap<String, String> property_;

    // 用户操作时按下的y坐标
    protected float yDown_;
    // 点击的x坐标值
    protected float xDown_;
    // 控件弹起时的坐标值
    public int xUp_;
    public int yUp_;
    // 滑动操作的参考距离,如果大于改比例像素才算作移动,有弹起的操作无效
    public final int offset_;
    // 默认小号字体大小
    static final int FONT_SIZE_SMALL = 20;
    // 默认中号字体大小
    static final int FONT_SIZE_MEDIUM = 24;
    // 默认大好字体大小
    static final int FONT_SIZE_LARGE = 30;
    /*************************************************************************
     * Select style.
     *************************************************************************/
    static final int SELECT_DEFAULT_TEXT_COLOR = Color.DKGRAY;
    static final int SELECT_DEFAULT_FONT_SIZE = FONT_SIZE_MEDIUM;
    static final int SELECT_DEFAULT_POP_BACKGROUD_COLOR = Color.DKGRAY;
    public static ArrayList VWIDGETARRAY;
    // 控件节点名称
    private String nodeName_;
    /** delay time */
    private int delaytime_;
    String attrHref_;
    public String attrValue_;
    String attrStyle_;
    /**
     * minimum of the characters
     */
    int minSize_;
    /**
     * maxmum of the characters
     */
    int maxSize_;
    /** Button images */
    public static int DOWN_IMG = 0;
    public static int NORMAL_IMG = 1;
    public static int FOCUS_IMG = 2;

    // 璇诲彇杩涘害鎻愮ず瀛椾綋澶у皬
    protected final int SIZE_IMGWAITLOAD = 15;
    // tabbar鎺т欢瀛椾綋澶у皬
    protected final int SIZE_TABBAR = 16;
    // 榛樿灏忓彿瀛椾綋澶у皬
    protected final int SIZE_SMALL = 20;
    // 榛樿涓彿瀛椾綋澶у皬
    protected final int SIZE_MEDIUM = 24;
    // 榛樿澶уソ瀛椾綋澶у皬
    protected final int SIZE_LARGE = 30;

    private static final int DEFAULT_VIEW_TOP_MARGIN = 10;
    // 鏃ユ湡鎺т欢鏍囪鍚�
    public static String viewLPDateFieldTag_;
    public static final int HL_BACKGROUND_COLOR = 0xFF2874DC;
    public static final int HL_TABBAR_COLOR = 0xFF405F87;
    static final int STATUS_BAR_COLOR = 0x008F8E88;
    static final int HL_FOREGROUND_COLOR = Color.WHITE;
    static final int BACKGROUND_COLOR = Color.WHITE;
    static final int FOREGROUND_COLOR = 0xFFFFFFFF;
    static final int HYPERLINK_UNDERLINE_COLOR = 0x808080;
    static final int SCROLL_BAR_BACKGROUND = 0x00C5C7C9;
    static final int SCROLL_BAR_FOREGROUND = 0x00808588;
    static final int ITEM_BACKGROUND_GREY = 0xd4d4d4;
    static final int COLOR_BUTTONTEXT = 0xFF000000;
    /*
     * HTML attributes
     */
    // name of XML node.
    private static final String ATTRIBUTE_NAME = "name";
    // value of XML node.
    private static final String ATTRIBUTE_VALUE = "value";
    // type of input node in XML documents.
    private static final String ATTRIBUTE_INPUT_TYPE = "type";
    // "src" attribute of XML node.
    private static final String ATTRIBUTE_SRC = "src";
    /*
     * Custom attributes from XHTML & XML
     */
    // text of the component.
    private static final String ATTRIBUTE_CONTENT_TEXT = "contentText";
    // if the component is required inputting.
    private static final String ATTRIBUTE_REQUIRED = "required";
    // accessory URI.
    private static final String ATTRIBUTE_ACCESSORY = "accessory";
    // style index.
    private static final String ATTRIBUTE_STYLE_INDEX = "styleIndex";
    // label of the component.(only for TextField)
    static final String ATTRIBUTE_LABEL = "label";

    private static int MAX_WIDTH = 300;
    protected static final int DEFAULT_STYLE_INDEX = 0;
    // protected static int MAX_ROW_WIDTH = SCREEN_WIDTH - 20;

    private static final int TOP = 0;
    private static final int BOTTOM = 1;
    private static final int LEFT = 2;
    private static final int RIGHT = 3;
    private int[] margins_;
    private int[] paddings_;

    // protected Activity bv_;
    // 控件样式定义,里面记录了从服务端传过来的样式各参数
    protected CssStyle cssStyle_;

    /* Component properties */
    // indicate the component needs to be encrypted.
    private boolean isEncrypt_;
    // Indicate the inputting is not empty.
    private String[] relaEnable_;
    private String[] relaDisable_;
    private String[] relaVisible_;
    private String[] relaInvisible_;
    // state of focusable.
    boolean focusable_;
    // state of focusable in touch model.
    private boolean focusableInTouchMode_;
    // state of visible. One of VISIBLE, INVISIBLE, or GONE
    int visiable_ = View.VISIBLE;
    // state of enable.
    private boolean isEnable_ = true;
    // whether drawing border
    private boolean isDrawBorder_ = true;
    // Event listener.
    protected ComponentListener listener_;
    // 控件列表widget.xml中的属性表
    public HashMap<String, String> attributes_;
    // 控件列表widget.xml中的type属性
    public String widgetType_;
    // 控件列表的宽高对应表
    static HashMap<String, String> WIDGETATTRIBUTES;
    // 默认字体颜色，该色值最初从config中读取
    public static int TEXTCOLOR;
    // the outer view which will be set into the ViewGroup.
    // the real view of this component which is in SelfLayout.
    public View realView_;
    // the parent actually on the screen.
    
    float[] matrixValues_ = new float[]{1f,0f,0f,0f,1f,0f,0f,0f,1f};
    public int width_;
    public int height_;
    public int animaExeCount_ = 1;// 记录控件执行动画的次数
    // 标志控件按下状态图片;
    public Bitmap focusImg_;
    // 控件未按下状态图片
    public Bitmap unFocusImg_;
    // 控件的父控件
    public LPLayout parent_;
    // 控件或者界面标记,该标记由lua脚本指定
    private String lpTag_;
    // 控件的父系节点控件，该变量与父控件有少许区别，父控件为实体控件，存在加载被加载关系，父系节点控件只是标注一下父子的从属关系
    public Component parentComponent_;
    /**
     * 饼图控件（饼图控件是组合控件并没有对应的标签而是由多个type为cake的input标签组成）
     */
    public LPPieChart pieChart_;

    /**
     * segment的父布局
     */
    public LPSegmentLayout segmentLayout_;

    public static ArrayList<LPRadio> radioList_;
    
    /**
     * 自身是否处于横向滚动条中。这个横向滚动条对象的值。
     */
    public HSView hs_ = null;
    /**
     * 自身是否处于纵向滚动条中，这个纵向滚动条对象的值。
     */
    public LPScrollView vs_ = null;
    /**
     * 控件所在的tr。
     */
    public Component tr_ = null;
    /**
     * 控件所在的ScrollView。
     */
    public Component llvSV_ = null;
    
    // 如果这个控件是按钮，那么有按下时候的背景图和抬起时候的背景图，这里仅仅记录一下图片的资源id。
    /**
     * 按钮按下时候的背景图id。
     */
    public int downBG_ = -1;
    /**
     * 移动或者抬起时候的背景图id。
     */
    public int upBG_ = -1;
    
    /**
     * 对于一个label，记录其最大行宽。
     */
    public float maxLineWidth_ = 0;
    
    /**
     * 分行中如果任何控件含有css样式，记录下来 add by cheng.l
     */
    public static boolean hasCssStyle = false;
    public void addView(Component c) {
    }

    /**
     * 多用于局部更新，先删除界面内容
     * */
    public void deleteChildComponent() {
        // TODO Auto-generated method stub
        if(this instanceof LPLayout){
            LPLayout lpout =  (LPLayout)this;
            int size = lpout.getChildCount();
            for (int i = size - 1; i >= 0; i--) {
                Component c = lpout.getChildAt(0);
                lpout.removeView(c);
//                releaseResource(c);
            }
        }
    }
    
    /**
     * 多用于局部更新，再添加新界面内容
     * 
     * @param cOMPONENTPARTLY
     */
    private Component addChildComponent(Component com) {
        if (!(this instanceof LPLayout) || !(com instanceof LPLayout)) {
            return null;
        }
        LPLayout toLpout = (LPLayout)this;
        LPLayout fromLpout = (LPLayout)com;
        int size = fromLpout.getChildCount();
        for (int i = 0; i < size; i++) {
            Component c = fromLpout.getChildAt(0);
            fromLpout.removeView(c);
            
            toLpout.addView(c);
        }
        
      /**
      * 将新控件的宽高赋值给老控件。并且赋值样式。
      */
     try{
     	// 老控件的布局参数。
     	AbsoluteLayout.LayoutParams oldLp =
     			(AbsoluteLayout.LayoutParams)toLpout.getLayoutParams();
     	int newX = ((AbsoluteLayout.LayoutParams)fromLpout.getLayoutParams()).x; // 新的左边距。
     	int newY = ((AbsoluteLayout.LayoutParams)fromLpout.getLayoutParams()).y; // 新的上边距。
     	int newWidth = 0; // 新的宽。
     	int newHeight = 0; // 新的高。
     	// 计算新的宽高。
     	if(fromLpout.width_ > 0){
     		newWidth = fromLpout.width_;
     	} else if(fromLpout.getLayoutParams().width > 0){
     		newWidth = fromLpout.getLayoutParams().width;
     	} else if(fromLpout.getWidth() > 0){
     		newWidth = fromLpout.getWidth();
     	}
     	if(fromLpout.height_ > 0){
     		newHeight = fromLpout.height_;
     	} else if(fromLpout.getLayoutParams().height > 0){
     		newHeight = fromLpout.getLayoutParams().height;
     	} else if(fromLpout.getHeight() > 0){
     		newHeight = fromLpout.getHeight();
     	}
     	// 赋值布局参数。
     	oldLp = new AbsoluteLayout.LayoutParams(newWidth, newHeight, newX, newY);
     	// 设置布局参数。
     	toLpout.setLayoutParams(oldLp);
     	toLpout.width_ = newWidth;
     	toLpout.height_ = newHeight;
     } catch (Exception e){}
        
        toLpout.invalidate();
        return toLpout;
    }

    public Animation getAnimation() {
        return realView_.getAnimation();
    }

    /**
     * 将控件的关键属性赋值给新的控件
     * 
     * @param cOMPONENTPARTLY
     */
    private Component copyPropertyToNewOne(Component cOMPONENTPARTLY) {
        // TODO Auto-generated method stub
        cOMPONENTPARTLY.isAfterBr_ = isAfterBr_;
        return cOMPONENTPARTLY;
    }

    public interface CompositedComponent {
        /**
         * @return the component which it's belong to.
         */
        Component composited();
    }

    /**
     * 
     */
    public Component() {
        offset_ = Utils.getScaledValueX(4);
        property_ = new HashMap();
    }

    void shrinkWidth() {
        // TODO Auto-generated method stub
    }

    void cleanText() {
        // TODO Auto-generated method stub
    }

    /**
     * 重新设置样式，并且刷新控件的显示效果
     * 
     * @param name
     * @param value
     */
    public void setStyleByName(final String name, final String value) {
    	if (name != null) {
    		final String tempKey = name.toString().trim().toLowerCase();
    		final String tempValue =  value != null ? value.toString().trim() : "";
    		
    		if(cssStyle_ == null){
    			cssStyle_ = new CssStyle();
    		}
    		
            try {

                if (Thread.currentThread().getId() == 1) {
                	cssStyle_.setProperty(tempKey, tempValue);
                	mouldCssStyleByName(tempKey , tempValue);
                    invalidate();

                } else {

                    getActivity().runOnUiThread(new Runnable() {

                        @Override
                        public void run() {

                        	cssStyle_.setProperty(tempKey, tempValue);
                        	mouldCssStyleByName(tempKey , tempValue);

                            invalidate();

                        }

                    });

                }

            } catch (Exception e) {

                // TODO Auto-generated catch block

                Utils.printException(e);
            }
        }
    }

    public Object getStyleByName(Object name) {
        String n = null;
        if (null != cssStyle_) {
            if (name instanceof String)
                n = (String) name;
            return String.valueOf(cssStyle_.getProperty(n));
        } else {
            return null;
        }
    }

    /**
     * Get the outer view which will be set into the ViewGroup.
     * 
     * @return
     */
    public View getLPView() {
        return realView_;
    }

    public String getNodeName() {
        // 返回控件的节点名称
        return nodeName_;
    }

    /**
     * Get the real view of this component which is in SelfLayout.
     * 
     * @return
     */
    protected View getRealView() {
        return realView_;
    }

    public void initRealView(Activity activity, String nodeValue) {
        // LayoutParams lp = getLayoutParams();
        if (realView_ != null) {
            // 此处的宽高xy设置应以Frame_参数定义为准，有机会需要修改
            realView_.setLayoutParams(prms);
        }
    }

    public void initWithParam() {
    }

    /**
     * @param v
     * @param ignoreView
     */
    public static void removeViewsStepByStep(View v, View ignoreView) {
        if (v == null || v == ignoreView) {
            return;
        }
        if (v instanceof ViewGroup) {
            ViewGroup vg = (ViewGroup) v;
            int size = vg.getChildCount();
            for (int i = 0; i < size; i++) {
                removeViewsStepByStep(vg.getChildAt(i), ignoreView);
            }
            vg.removeAllViews();
        }
    }

    /**
     * 
     */
    public void refresh() {
        if (realView_ != null) {
            realView_.invalidate();
        }
    }

    /**
     * @param font
     * @param string
     */
    protected void setTypeFace(TextPaint font, String string) {
        if (font == null) {
            return;
        }
        font.setTypeface(getTypeFace(string));
        if (string != null) {
            font.setFakeBoldText(getFontType(string));
        }
    }

    /**
     * 璁剧疆瀛椾綋鏄惁绮椾綋
     * */
    private static boolean getFontType(String string) {
        if (string.equalsIgnoreCase("bold")) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * @param string
     * @return
     */
    protected static Typeface getTypeFace(String string) {
        Typeface tface = null;
        try {
            if (string.equalsIgnoreCase("bold")) {
                tface = Typeface.defaultFromStyle(Typeface.BOLD);
            } else if (string.equalsIgnoreCase("normal")) {
                tface = Typeface.defaultFromStyle(Typeface.NORMAL);
            } else {
                tface = null;
            }
        } catch (Exception e) {
            tface = null;
        }
        return tface;
    }

    public void postInvalidate() {

        if (realView_ != null) {

            if (Thread.currentThread().getId() != 1)

                realView_.postInvalidate();

            else

                realView_.invalidate();

        }

    }

    public void invalidate() {

        // TODO Auto-generated method stub

        if (null != realView_) {

            if (Thread.currentThread().getId() == 1)

                realView_.invalidate();

            else

                realView_.postInvalidate();

        }

    }

    /**
     * @return
     */
    public boolean isShown() {
        if (realView_ != null) {
            return realView_.isShown();
        }
        return false;
    }

    /**
     * get the layout parameters of the component view
     * 
     * @return
     */
    public LayoutParams getLayoutParams() {
        if (realView_ == null) {
            return null;
        }
        return realView_.getLayoutParams();
    }

    /**
     * 判断是否超过移动范围，如果是，则响应上层控件移动方法
     * 
     * @param yDown_
     * @param y
     */
    public void moveY(float yDown_, float y) {
        // TODO Auto-generated method stub
        if (null != parent_) {
            parent_.moveY(yDown_ - y);
        }
    }

    public boolean isDrawBorder_() {
        return isDrawBorder_;
    }

    public void setDrawBorder_(boolean isDrawBorder_) {
        this.isDrawBorder_ = isDrawBorder_;
    }

    /*
     * ************************************************************************
     * Facade mould methods. ************************************************************************
     */
    /**
     * 该方法主要用于指定控件的大小\显示颜色\样式等,如果服务端没有给定输出样式大小,则要自行计算一个合适的大小应用于该控件
     * Mould this component with its shape, color, size and
     * so on.
     * 
     * @return
     * @throws Exception
     *             TODO
     */
    public void mouldW() throws Exception {
        String tag = getTag();
        if (null == realView_)
            return;
        String enable = getPropertyByName("enable");
        if (enable.equalsIgnoreCase("yes")) {
            setEnable(true);
        } else if (enable.equalsIgnoreCase("no")) {
            setEnable(false);
        }
        // 初始化parent_对象，在界面点击移动时会用到
        Object parentO = getParent();
        if (parentO instanceof LPLayout)
            parent_ = (LPLayout) parentO;
        // 从配置文件Config里面读取时差值，主要用于判定用户点击是否是连击
        jetLag_ = Utils.jat_lag;
        int w = 0;
        int h = 0;
        ViewGroup vGroup = (ViewGroup) realView_.getParent();
        // 由于整个应用框架采用的是绝对布局，所以必须对控件指定宽高及位置
        if (null != cssStyle_) {
            // 设置和位置宽高相关的样式
            String cssValue = cssStyle_.getProperty(CssStyle.WIDTH);
            w = Integer.parseInt(fixedPX(cssValue));
            // w = Utils.getScaledValueX(w);
            cssValue = cssStyle_.getProperty(CssStyle.HEIGHT);
            h = Integer.parseInt(fixedPX(cssValue));
            // h = Utils.getScaledValueY(h);
            // 当w和h值一样时，做特殊处理，使其缩放后相等
            if (w > 0 || h > 0) {
                if (w == h) {
                    if (SCREENWIDTH < SCREENHEIGHT) {
                        // 竖屏显示应按横向比去缩放，保证正形比例且不超屏
                        w = Utils.getScaledValueX(w);
                        h = Utils.getScaledValueX(h);
                    } else {
                        w = Utils.getScaledValueY(w);
                        h = Utils.getScaledValueY(h);
                    }
                } else {
                    w = Utils.getScaledValueX(w);
                    h = Utils.getScaledValueY(h);
                }
            }
            String display = cssStyle_.getProperty(CssStyle.DISPLAY);
            if (display != null && display.equals("none")) {
                setVisible(View.GONE);
            }
        }
        
        // 修正控件输出参数，保证其尽量合理
        if (w <= 0) {
            // 统一先取widget中配置的宽度
            w = getAcquiescentWidth();
			
			//如果是分行中除了body控件大于300的手动设置为300
            if(LPToastUtil.getInstance().isBranchBank){
            	if(null != cssStyle_ && !Component.hasCssStyle){
            		Component.hasCssStyle = true;
            	}
            	
            	if(!Component.hasCssStyle && null != getTag() && null == cssStyle_&& !"body".equalsIgnoreCase(getTag())){
            		if(w >=Utils.getScaledValueX(300)){
            			w = Utils.getScaledValueX(300);
            		}
            	}
            }
            
            
            if (w <= 0) { // 没有读到值。
                if (null != tag && tag.equalsIgnoreCase("body")){
                    // 如果没有配置宽度，则将整个界面的宽度赋给body
                    w = SCREENWIDTH;
                } else if(getTag().equalsIgnoreCase("th") || getTag().equalsIgnoreCase("td")){
                	int size = parent_.getChildCount();
                	// 计算之前已经确定了宽度的td的个数和总宽度。
                	int sureTotalWidth = 0; // 已经确定了宽度的td的总宽度。
                	int sureNumber = 0; // 已经确定了宽度的td的个数。
                	for (int i = 0; i < size - 1; i++) {
						LPLayout td = (LPLayout) parent_.getChildAt(i);
						if(td != null && td.cssStyle_ != null
								&& td.cssStyle_.getProperty(CssStyle.WIDTH) != null
								&& !"".equals(td.cssStyle_.getProperty(CssStyle.WIDTH))){
							sureNumber++;
							sureTotalWidth += Math.max(td.width_, td.getLayoutParams().width);
						}
					}
                    // 赋值之前宽度没有确定的td的宽。
                    for(int i = 0 ; i < size - 1 ; i++){
                        LPLayout td = (LPLayout)parent_.getChildAt(i);
                        if(td != null && td.cssStyle_ != null
                        		&& td.cssStyle_.getProperty(CssStyle.WIDTH) != null
                        		&& !"".equals(td.cssStyle_.getProperty(CssStyle.WIDTH))){}
                        else {
                        	int tdWidth = 0;
                        	if(size - sureNumber > 0){
                        		tdWidth = (int) ((parent_.width_ - sureTotalWidth) * 1.0f / (size - sureNumber));
                        	}
                        	td.getLayoutParams().width = tdWidth;
                        	td.width_ = tdWidth;
                        }
                    }
                    // 给自己赋值宽度。
                    if(size - sureNumber > 0){
                    	w = (int) ((parent_.width_ - sureTotalWidth) * 1.0f / (size - sureNumber));
                    }
                } else{ // 如果不是td或者th，那么宽度取父控件的宽度。
                    w = parent_.width_;
                }
            }
        }

        width_ = w;
        height_ = h;
        if (vGroup instanceof FrameLayout) {
            final android.widget.FrameLayout.LayoutParams fl = new android.widget.FrameLayout.LayoutParams(w, h);
            if (Thread.currentThread().getId() == 1) {
                realView_.setLayoutParams(fl);
            } else {
                if (null != realView_) {
                    ((Activity) getContext()).runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            realView_.setLayoutParams(fl);
                        }

                    });
                }
            }
        } else if (null != tag && tag.equalsIgnoreCase("body")) {
            final android.widget.FrameLayout.LayoutParams fl = new android.widget.FrameLayout.LayoutParams(w, h);
            if (Thread.currentThread().getId() == 1) {
                realView_.setLayoutParams(fl);
            } else {
                if (null != realView_) {
                    ((Activity) getContext()).runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            realView_.setLayoutParams(fl);
                        }

                    });
                }
            }
        } else {
            // 如果控件标记不为body，则对其限制大小
            LayoutParams lp = new android.widget.AbsoluteLayout.LayoutParams(w, h, 0, 0);
            setLayoutParams(lp);
        }

        mouldTextView();
        setBGColor();
    }

    public void mouldH() throws Exception {
        String tag = getTag();
        if (null == realView_)
            return;
        // 初始化parent_对象，在界面点击移动时会用到
        Object parentO = getParent();
        if (parentO instanceof LPLayout)
            parent_ = (LPLayout) parentO;
        // 从配置文件Config里面读取时差值，主要用于判定用户点击是否是连击
        jetLag_ = Utils.jat_lag;
        int w = 0;
        int h = 0;
        ViewGroup vGroup = (ViewGroup) realView_.getParent();
        // 由于整个应用框架采用的是绝对布局，所以必须对控件指定宽高及位置
        if (null != cssStyle_) {
            // 设置和位置宽高相关的样式
            String cssValue = cssStyle_.getProperty(CssStyle.WIDTH);
            w = Integer.parseInt(fixedPX(cssValue));
            cssValue = cssStyle_.getProperty(CssStyle.HEIGHT);
            // 设置和位置宽高相关的样式
            h = Integer.parseInt(fixedPX(cssValue));
            // 当w和h值一样时，做特殊处理，使其缩放后相等
            if (h > 0) {
                if (w == h) {
                    if (SCREENWIDTH < SCREENHEIGHT) {
                        // 竖屏显示应按横向比去缩放，保证正形比例且不超屏
                        h = Utils.getScaledValueX(h);
                    } else {
                        h = Utils.getScaledValueY(h);
                    }
                } else {
                    h = Utils.getScaledValueY(h);
                }
            }
        }
        if (h <= 0) {
            if (vGroup instanceof FrameLayout) {
                h = FrameLayout.LayoutParams.MATCH_PARENT;
            } else if (null != tag && tag.equalsIgnoreCase("tr")) {
                h = hSelfMax_;
                // 读取widget设置的tr高度为tr高度的最小值
                if (h <= getAcquiescentHeight())
                    h = getAcquiescentHeight();
                // 如果没有读到值的话设置tr高度为包裹内容。【仍需研究】
                if (h <= 0)
                	h = android.widget.AbsoluteLayout.LayoutParams.WRAP_CONTENT;
            } else if (null != tag && (tag.equalsIgnoreCase("td") || tag.equalsIgnoreCase("th"))) {
                // 如果是td列控件,则要求高度充满整个tr
                h = AbsoluteLayout.LayoutParams.FILL_PARENT;
            } else if (this instanceof LPLayout) {
                if (null != tag && tag.equalsIgnoreCase("body"))
                    h = LayoutParams.MATCH_PARENT;
                else
                    h = hSelfMax_;
            } else {
                h = getAcquiescentHeight();
            }
        }
        height_ = h;
        if (vGroup instanceof FrameLayout) {
            final android.widget.FrameLayout.LayoutParams fl = (android.widget.FrameLayout.LayoutParams) realView_
                    .getLayoutParams();
            fl.height = height_;
            if (Thread.currentThread().getId() == 1) {
                realView_.setLayoutParams(fl);
            } else {
                if (null != realView_) {
                    ((Activity) getContext()).runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            realView_.setLayoutParams(fl);
                        }

                    });
                }
            }
        } else if (null != tag && tag.equalsIgnoreCase("body")) {
            final android.widget.FrameLayout.LayoutParams fl = (android.widget.FrameLayout.LayoutParams) realView_
                    .getLayoutParams();
            fl.height = height_;
            if (Thread.currentThread().getId() == 1) {
                realView_.setLayoutParams(fl);
            } else {
                if (null != realView_) {
                    ((Activity) getContext()).runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            realView_.setLayoutParams(fl);
                        }

                    });
                }
            }
        } else {
            // 如果控件标记不为body，则对其限制大小
            LayoutParams lp = realView_.getLayoutParams();
            if (lp == null) {
                lp = new LayoutParams(w, h);
            }
            lp.height = height_;
            setLayoutParams(lp);
        }
        // 寻找控件所处的tr。
        tr_ = Utils.getTR(this);
    }

    public void setBGColor() {
        // input类控件（raido checkbox text）等不参与背景色的统一设置，可单独处理
        if (null != getTag()
                && (getTag().equalsIgnoreCase("input") || getTag().equalsIgnoreCase("select") || getTag()
                        .equalsIgnoreCase("pie")))
            return;
        // 背景色在背景图片定义之后方才有效
        if (null != cssStyle()
                && null != cssStyle().content_
                && cssStyle().content_.indexOf(CssStyle.BGIMAGEURL) > cssStyle().content_
                        .indexOf(CssStyle.BACKGROUNDCOLOR))
            return;
        // TODO Auto-generated method stub
        String bw = (String) getPropertyByName("border");
        if ("tr".equalsIgnoreCase(getTag()) || "th".equalsIgnoreCase(getTag()) || "td".equalsIgnoreCase(getTag())) {
            bw = "";
        }
        if (null != bw && !bw.equals("") && bw.indexOf("0") != -1) {
            // border为零表示无边框,但是需要绘制背景色
            String temp = getAttribute("BackgroundColor_");
            if (null == temp || temp.equals("")) {
                temp = "#00000000";
            }
            int bgColor = Color.parseColor(temp);
            if (cssStyle_ != null) {
                temp = (String) cssStyle_.getProperty(CssStyle.BACKGROUNDCOLOR);
                if (null != temp && !temp.equals("")) {
                    bgColor = Color.parseColor(temp);
                }
            }
            realView_.setBackgroundColor(bgColor);
        } else if (bw.equals("")) {
            if (null != getTag() && (getTag().equalsIgnoreCase("table") || getTag().equalsIgnoreCase("div"))) {
                // div和table的默认背景在绘制边框的时候绘制,这两个框架默认的是圆角背景
                return;
            } else {
                String temp = getAttribute("BackgroundColor_");
                if (null == temp || temp.equals("")) {
                    temp = "#00000000";
                }
                int bgColor = Color.parseColor(temp);
                if (cssStyle_ != null) {
                    temp = (String) cssStyle_.getProperty(CssStyle.BACKGROUNDCOLOR);
                    if (null != temp && !temp.equals("")) {
                        bgColor = Color.parseColor(temp);
                    }
                }
                // 如果是tr控件，单纯设置背景色会使tr被绘制成方角矩形，但是在table的首尾两个tr一般是圆角的。因此需要单独调用tr的设置背景色方法。
                if(getTag() != null && getTag().equalsIgnoreCase("tr")){
                	// 如果tr被设置了背景色或者背景样式，那么就进行tr的背景色绘制。
                	if(cssStyle_ != null &&
                			(cssStyle_.getProperty(CssStyle.BACKGROUNDCOLOR) != null
                			|| cssStyle_.getProperty(CssStyle.COLOR) != null
                			|| cssStyle_.getProperty(CssStyle.FILTER) != null)){
                		((MyLPLayout) realView_).isSpecialTRBg_ = true;
                	}
                } 
                // 有时候后台会给td设置背景色样式，那么依然要单独处理。
                else if(getTag() != null && getTag().equalsIgnoreCase("td")){
                	// 如果td被设置了背景色或者背景样式，那么就进行td背景色绘制。
                	if(cssStyle_ != null &&
                			(cssStyle_.getProperty(CssStyle.BACKGROUNDCOLOR) != null
                			|| cssStyle_.getProperty(CssStyle.COLOR) != null
                			|| cssStyle_.getProperty(CssStyle.FILTER) != null)){
                		((MyLPLayout) realView_).isSpecialTDBg_ = true;
                	}
                } else {
                	realView_.setBackgroundColor(bgColor);
                }
            }
        }
    }

    /**
     * 获取默认的控件高度值，如果后台未限制控件的高度，控件的宽度有可能根据该值决定，该值取widget.xml中的对应控件的Frame_值
     * 
     * @return
     */
    protected int getAcquiescentHeight() {
        // TODO Auto-generated method stub
        if (null == widgetType_)
            widgetType_ = "";
        if (null != WIDGETATTRIBUTES && null != WIDGETATTRIBUTES.get(getTag().concat(widgetType_))) {
            acquiescentHeight_ = Utils.getScaledValueY(Integer.parseInt((WIDGETATTRIBUTES.get(getTag().concat(
                    widgetType_).concat("h"))).toString()));
        } else {
            if (null == WIDGETATTRIBUTES)
                WIDGETATTRIBUTES = new HashMap<String, String>();
            if (null == attributes_)
                return acquiescentHeight_ = 0;
            String frame = attributes_.get("Frame_");
            String temp = frame;
            if (null != temp && temp.contains(",")) {
                acquiescentHeight_ = Utils.getScaledValueY(Integer.parseInt(temp.substring(temp.lastIndexOf(",") + 1)));
                WIDGETATTRIBUTES.put(getTag().concat(widgetType_).concat("h"),
                        temp.substring(temp.lastIndexOf(",") + 1));
            }
        }
        return acquiescentHeight_;
    }
    
    /**
     * 重设checkbox或者radiobutton的规格参数，当需要显示的文字过长时候进行换行。
     * 
     * @param gap 文字左边的间隔距离。
     */
    protected void reSetTextLayoutParams(int gap){
    	try{
    		// 如果拿到的文字信息为空，就不必进行下面的工作了。
    		if(property_ == null || property_.get("text") == null
    				|| "".equalsIgnoreCase(property_.get("text"))){
    			return;
    		}
    		Paint paint = null; // 用到的画笔。
    		if(realView_ instanceof MyLPRadio){
    			paint = ((MyLPRadio) realView_).getPaint();
    		} else if(realView_ instanceof MyLPCheckBox){
    			paint = ((MyLPCheckBox) realView_).getPaint();
    		}
    		LayoutParams viewLayout = getLayoutParams(); // 用到的布局。
    		int w = width_; // 存储宽度。
    		int h = height_; // 存储高度。
    		if (cssStyle_ == null ||
            		(cssStyle_ != null && (cssStyle_.getProperty(CssStyle.WIDTH) == null
            		|| "".equalsIgnoreCase(cssStyle_.getProperty(CssStyle.WIDTH))))) {
    			// 如果没有拿到宽度，那么宽度取父控件的宽度和内容宽度的较小值。
    			int parentWidth = Math.max(parent_.width_, parent_.getWidth()); // 父控件宽。
            	int contentWidth = (int) Math.ceil(gap + paint.measureText(property_.get("text"))); // 内容宽。
            	// 需要计算应减去的左右边距。
            	int left = 0;
            	int right = 0;
            	try{
            		if(cssStyle_ != null){
            			if(cssStyle_.getProperty(CssStyle.LEFT) != null && !"".equalsIgnoreCase(cssStyle_.getProperty(CssStyle.LEFT))){
            				String leftStr = cssStyle_.getProperty(CssStyle.LEFT);
            				left = Utils.getScaledValueX(Float.parseFloat(Component.fixedPX(leftStr)));
            			}
            			if(cssStyle_.getProperty(CssStyle.RIGHT) != null && !"".equalsIgnoreCase(cssStyle_.getProperty(CssStyle.RIGHT))){
            				String rightStr = cssStyle_.getProperty(CssStyle.RIGHT);
            				right = Utils.getScaledValueX(Float.parseFloat(Component.fixedPX(rightStr)));
            			}
            		}
            	}catch (Exception e) {
				}
            	if(parentWidth == 0){ // 没拿到父控件的宽度，直接赋值内容宽。
            		width_ = contentWidth;
            	} else {
            		width_ = Math.min(parentWidth, contentWidth);
            	}
            	// 计算左右边距。
            	if(width_ + left >= parentWidth){
            		width_ -= left;
            	}
            	if(width_ + right >= parentWidth){
            		width_ -= right;
            	}
            } else {
                width_ = w;
            }
    		// 将要显示的文字拆分成数组 分行显示
            stringArr_ = Utils.getParagraph(property_.get("text"), paint, width_ - gap);
            // 计算最大行宽。
            if(stringArr_ != null && stringArr_.length > 0){
            	for (int i = 0; i < stringArr_.length; i++) {
            		if(stringArr_[i].endsWith("\n")){
            			maxLineWidth_ = Math.max(maxLineWidth_, 
            					paint.measureText(stringArr_[i].substring(0, stringArr_[i].lastIndexOf("\n"))));
            		} else {
            			maxLineWidth_ = Math.max(maxLineWidth_, paint.measureText(stringArr_[i]));
            		}
				}
            }
            // FontMetrics fm = paint.getFontMetrics();
            // int tHeight = (int) (Math.ceil(fm.descent - fm.ascent)); // 计算文字的高度
            int tHeight = ((int) (paint.getTextSize() * 3)) >> 2;
            // int tHeight = (int) Math.round(((int) (paint.getTextSize() * 3)) / 4.0f);
    		// 计算总高度。
    		int realHeight = height_;
    		if (null != stringArr_) {
    			// 高度=每行的高度*行数+两行之间的行间距+控件上下的留白高度
    			realHeight = (int) ((tHeight) * stringArr_.length + Utils.getScaledValueY(SPACE_Y_)
    					* (stringArr_.length - 1) + Utils.getScaledValueY(blankY_ << 1));
    			if (Component.SCREENWIDTH == 240 && stringArr_.length == 1)
    				realHeight = (int) (paint.getTextSize() * 4 / 3);
    		}
    		// 如果没有给高度或者给定的高度小于文字总高度。
            if (h <= 0 || h < realHeight) {
            	height_ = realHeight;
            } else {
                height_ = h;
            }
            viewLayout.width = width_;
            // 为了能够完整显示gjpy等小写字母，特别加上一段高度。
            viewLayout.height = height_ + Utils.getScaledValueY(3);
            setLayoutParams(viewLayout);
    	}catch(Exception e1){
    		Utils.printException(e1);
    	}
    }

    /**
     * 重设LPLable的规格参数 该方法中stringArr_只是协助计算一个大概的宽高值。 
     * label的宽高如果后台没有提供，不能单纯的只参考widget控件列表的参数，还应根据实际内容计算出实际大小
     * */
    protected void reSetTextViewLayoutParams() {
        try {
            TextView mlpl = (TextView) realView_;
            final Paint paint = mlpl.getPaint();
            LayoutParams viewLayout = null;
            viewLayout = (LayoutParams) getLayoutParams();
            String align = null;
            int w = 0;
            int h = 0;
            if (null != cssStyle_) {
                if (null != cssStyle_.getProperty(CssStyle.WIDTH) && !cssStyle_.getProperty(CssStyle.WIDTH).equals("")) {
                    w = Integer.parseInt(fixedPX((String) cssStyle_.getProperty(CssStyle.WIDTH)));
                    w = Utils.getScaledValueX(w);
                }
                if (null != cssStyle_.getProperty(CssStyle.HEIGHT)
                        && !cssStyle_.getProperty(CssStyle.HEIGHT).equals("")) {
                    h = Integer.parseInt(fixedPX((String) cssStyle_.getProperty(CssStyle.HEIGHT)));
                    h = Utils.getScaledValueY(h);
                }
                if (null != cssStyle_.getProperty(CssStyle.TEXTALIGN)
                        && !cssStyle_.getProperty(CssStyle.TEXTALIGN).equals("")) {
                    align = (String) cssStyle_.getProperty(CssStyle.TEXTALIGN);
                }
            }

            if (cssStyle_ == null ||
            		(cssStyle_ != null && (cssStyle_.getProperty(CssStyle.WIDTH) == null
            		|| "".equalsIgnoreCase(cssStyle_.getProperty(CssStyle.WIDTH))))) {
            	// 如果label没有拿到宽度，那么宽度取父控件的宽度和内容宽度的较小值。
            	int parentWidth = Math.max(parent_.width_, parent_.getWidth()); // 父控件宽。
            	int contentWidth = (int) Math.ceil(paint.measureText(getContentText())); // 内容宽。
            	// 内容宽需要减去左边距和右边距。
            	int left = 0;
            	int right = 0;
            	try{
            		if(cssStyle_ != null){
            			if(cssStyle_.getProperty(CssStyle.LEFT) != null && !"".equalsIgnoreCase(cssStyle_.getProperty(CssStyle.LEFT))){
            				String leftStr = cssStyle_.getProperty(CssStyle.LEFT);
            				left = Utils.getScaledValueX(Float.parseFloat(Component.fixedPX(leftStr)));
            			}
            			if(cssStyle_.getProperty(CssStyle.RIGHT) != null && !"".equalsIgnoreCase(cssStyle_.getProperty(CssStyle.RIGHT))){
            				String rightStr = cssStyle_.getProperty(CssStyle.RIGHT);
            				right = Utils.getScaledValueX(Float.parseFloat(Component.fixedPX(rightStr)));
            			}
            		}
            	}catch (Exception e) {
				}
            	if(parentWidth == 0){ // 没拿到父控件的宽度，直接赋值内容宽。
            		width_ = contentWidth;
            	} else {
            		width_ = Math.min(parentWidth, contentWidth);
            	}
            	// 计算左右边距。
            	if(width_ + left >= parentWidth){
            		width_ -= left;
            	}
            	if(width_ + right >= parentWidth){
            		width_ -= right;
            	}
            	
            	/**
            	 * 重新计算label宽度时，分行特殊处理
            	 */
				if (LPToastUtil.getInstance().isBranchBank
						&& !Component.hasCssStyle && null != getTag()
						&& null == cssStyle_
						&& "label".equalsIgnoreCase(getTag())) {
					width_ = Utils.getScaledValueX(300);
				}
            } else {
                width_ = w;
                if (align != null && align.equals("center")) {
                    int padding = (width_ - ((int) (paint.measureText(getContentText())) + 1)) >> 1;
                    mlpl.setPadding(padding, mlpl.getPaddingTop(), padding, mlpl.getPaddingBottom());
                } else if (align != null && align.equals("right")) {
                    int padding = width_ - ((int) (paint.measureText(getContentText())) + 1);
                    mlpl.setPadding(padding, mlpl.getPaddingTop(), mlpl.getPaddingRight(), mlpl.getPaddingBottom());
                }
            }
            
            // 替换特殊字符。
            setContentText(getContentText().replace("\t", ""));
            // 如果这个label带有rectcolor属性，而且加上一段矩形的宽度后仍然不超过父控件的宽度，那么需要在前面增加一段宽度用来绘制方块。
            if(getPropertyByName("rectcolor") != null && !"".equals(getPropertyByName("rectcolor"))
            		&& width_ + LPLabel.RECT_WIDTH_ <= Math.max(parent_.width_, parent_.getWidth())){
            	width_ += LPLabel.RECT_WIDTH_;
            	stringArr_ = Utils.getParagraph(getContentText(), paint, width_);
            }
            // 如果这个label带有rectcolor属性，加上一段矩形后宽度超过了父控件的宽度，那么在拆分字符串数组的时候需要减少拆分的标准长。
            else if(getPropertyByName("rectcolor") != null && !"".equals(getPropertyByName("rectcolor"))
            		&& width_ + LPLabel.RECT_WIDTH_ > Math.max(parent_.width_, parent_.getWidth())){
            	stringArr_ = Utils.getParagraph(getContentText(), paint, width_ - LPLabel.RECT_WIDTH_);
            }
            // 其它情况正常拆分。
            else {
            	stringArr_ = Utils.getParagraph(getContentText(), paint, width_);
            }
            // 计算最大行宽。
            if(stringArr_ != null && stringArr_.length > 0){
            	for (int i = 0; i < stringArr_.length; i++) {
            		if(stringArr_[i].endsWith("\n")){
            			maxLineWidth_ = Math.max(maxLineWidth_, 
            					paint.measureText(stringArr_[i].substring(0, stringArr_[i].lastIndexOf("\n"))));
            		} else {
            			maxLineWidth_ = Math.max(maxLineWidth_, paint.measureText(stringArr_[i]));
            		}
				}
            }
            // 计算label的高度。
            // int tHeight = (int) Math.round(((int) (paint.getTextSize() * 3)) / 4.0f);
            int tHeight = ((int) (paint.getTextSize() * 3)) >> 2; // 设定的文字高度。
            if (h <= 0) {
                if (stringArr_ != null && stringArr_.length > 0) {
                    // 高度=每行的高度*行数+两行之间的行间距+控件上下的留白高度
                    height_ = (int) ((tHeight) * stringArr_.length + Utils.getScaledValueY(SPACE_Y_)
                            * (stringArr_.length - 1) + Utils.getScaledValueY(blankY_ << 1));
                    if (Component.SCREENWIDTH == 240 && stringArr_.length == 1)
                        height_ = (int) (paint.getTextSize() * 4 / 3);
                }
            } else {
                height_ = h;
            }
            // 如果这个label带有lineNumber属性，则重新设置其高度。
            try{
            	int lineNumber = Integer.parseInt(getPropertyByName("lineNumber"));
            	if(lineNumber > 0 && stringArr_ != null && stringArr_.length > 0){
                    height_ = (int) ((tHeight) * lineNumber + Utils.getScaledValueY(SPACE_Y_)
                            * (lineNumber - 1) + Utils.getScaledValueY(blankY_ << 1));
                    if (Component.SCREENWIDTH == 240 && lineNumber == 1)
                        height_ = (int) (paint.getTextSize() * 4 / 3);
            	}
            } catch (Exception e){}
            // 如果这个label带有loop属性，则强制使其高度为1行。
            try{
            	String loop = getPropertyByName("loop");
            	if(loop != null && "true".equalsIgnoreCase(loop)){ // 有跑马灯效果。
            		height_ = (int) ((tHeight) +  + Utils.getScaledValueY(blankY_ << 1));
                    if (Component.SCREENWIDTH == 240)
                        height_ = (int) (paint.getTextSize() * 4 / 3);
            	}
            } catch (Exception e){}
            viewLayout.width = width_;
            // 为了能够完整显示gjpy等小写字母，特别加上一段高度。
            viewLayout.height = height_ + Utils.getScaledValueY(3);
            setLayoutParams(viewLayout);
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            Utils.printException(e1);
        }
    }

    public Paint getPaint() {
        if (realView_ instanceof TextView) {
            TextView temp = (TextView) realView_;
            return temp.getPaint();
        }
        return null;

    }

    /**
     * 依据Css样式，设置TextView类控件的相关属性
     */
    private void mouldTextView() {
        // TODO Auto-generated method stub
        if (realView_ instanceof TextView) {
            // 如果控件继承的是textview,则统一设置字体等属性
            TextView mlpl = (TextView) realView_;
            Paint paint = mlpl.getPaint();
            // 设置字体或者绘制效果平滑
            paint.setAntiAlias(true);
            String tag = getTag();
            if (null != tag && (tag.equalsIgnoreCase("i") || getTag().equalsIgnoreCase("em"))) {
                // 如果是i节点或者是em节点,则表示显示内容应该为斜体
//                mlpl.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
                paint.setTextSkewX(-0.3f);
            }
            if (null != tag && (tag.equalsIgnoreCase("b") || tag.equalsIgnoreCase("strong"))) {
                // 如果是b节点或者是strong节点,则表示显示内容应该为粗体
                paint.setFakeBoldText(true);
            }

            if (null != cssStyle_) {
                // 设置字体大小
                String temp = cssStyle_.getProperty(CssStyle.FONTSIZE);
                if (null != temp && !temp.equals("")) {
                    int fontSize = Integer.parseInt(fixedPX(temp));
                    fontSize = Utils.getFontSize(fontSize);
                    if (fontSize > 0) {
                        mlpl.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize);
                        paint.setTextSize(fontSize);
                    }
                }
                // 设置字体颜色
                temp = null;
                temp = cssStyle_.getProperty(CssStyle.COLOR);
                mlpl.setTextColor(Component.TEXTCOLOR);
                if (null != temp && !temp.equals("")) {
                    int cs_fontColor = Utils.getColorValue(temp);
                    // 设置画笔颜色
                    mlpl.setTextColor(cs_fontColor);
                    paint.setColor(cs_fontColor);
                    // 由于服务端暂时没有针对输入框提示文字颜色的设置,所以暂时设定为与输入一样的字体颜色
                    // 输入框提示文字颜色不用设置，用默认值即可
                    // mlpl.setHintTextColor(cs_fontColor);
                }
                // 设置字体权重
                temp = null;
                temp = cssStyle_.getProperty(CssStyle.FONTWEIGHT);
                if (null != temp && !temp.equals("")) {
                    setTypeFace((TextPaint) paint, temp);
                }

                // 设置字体对齐方式
                temp = null;
                temp = cssStyle_.getProperty(CssStyle.TEXTALIGN);
                if (null != temp && !temp.equals("") && null != cssStyle_.getProperty(CssStyle.WIDTH)) {
                    if (temp.equalsIgnoreCase("left")) {
                        mlpl.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
                    } else if (temp.equalsIgnoreCase("right")) {
                        mlpl.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
                        if (this instanceof LPLabel)
                            coordinate_x = width_ - ((int) (paint.measureText(getContentText())) + 1);
                    } else if (temp.equalsIgnoreCase("center")) {
                        mlpl.setGravity(Gravity.CENTER);
                        if (this instanceof LPLabel)
                            coordinate_x = (width_ - ((int) (paint.measureText(getContentText())) + 1)) >> 1;
                    }
                }
            }
        }
    }

    /**
     * 使用的时候滤出结尾的px值
     * 
     * @param property
     * @return
     */
    public static String fixedPX(Object property) {
        // TODO Auto-generated method stub
        if (property instanceof String) {
            String temp = ((String) property);
            if (null == temp || temp.equals(""))
                return "0";
            if (temp.contains("px"))
            	return temp.substring(0, temp.lastIndexOf("px"));
            else
                return temp;
        } else if (property instanceof Integer) {
            return String.valueOf(property);
        } else {
            return "0";
        }
    }

    protected Bitmap scaledBitmapByCSS(Bitmap bitmap) {
        if (null != bitmap) {
            String w = (String) cssStyle_.getProperty(CssStyle.WIDTH);
            String h = (String) cssStyle_.getProperty(CssStyle.HEIGHT);
            float wi = 0;
            float hi = 0;
            if (null != w && !w.equals("")) {
                wi = Utils.getScaledValueX(Float.parseFloat(fixedPX(w)));
            }
            if (null != h && !h.equals("")) {
                hi = Utils.getScaledValueY(Float.parseFloat(fixedPX(h)));
            }

            if (wi > 0 && hi > 0 && (wi != bitmap.getWidth() || hi != bitmap.getHeight())) {
                bitmap = Bitmap.createScaledBitmap(bitmap, (int) wi, (int) hi, true);
            } else if (wi > 0 && hi <= 0 && wi != bitmap.getWidth()) {
                hi = wi * bitmap.getHeight() / bitmap.getWidth();
                bitmap = Bitmap.createScaledBitmap(bitmap, (int) wi, (int) hi, true);
            } else if (wi <= 0 && hi > 0 && hi != bitmap.getHeight()) {
                wi = hi * bitmap.getWidth() / bitmap.getHeight();
                bitmap = Bitmap.createScaledBitmap(bitmap, (int) wi, (int) hi, true);
            }
            return bitmap;
        }
        return null;
    }

    public void mouldCssStyle() {
        String bgImageUrl = cssStyle_.getProperty(CssStyle.BGIMAGEURL);
        String display = cssStyle_.getProperty(cssStyle_.DISPLAY);
        String enable = cssStyle_.getProperty(cssStyle_.ENABLE);
        if (null != display && !display.equals("")) {
            if (display.equals("none")) {
                setVisible(View.GONE);
                // 如果隐藏直接让其返回
                return;
            } else if (display.equals("block")) {
                setVisible(View.VISIBLE);
            }
        }
        if (null != enable && !enable.equals("")) {
            if (enable.equals("true")) {
                setEnable(true);
            } else if (enable.equals("false")) {
                setEnable(false);
            }
        }
        if (null != bgImageUrl && !bgImageUrl.equals("")) {
            // 根据样式定义控件选中图片
            unFocusImg_ = Utils.getBitmapFromResources(getContext(), bgImageUrl);
            // 用户点击的图片也应该有样式定义,此处暂时设置为未点击时的去色效果
            focusImg_ = Utils.getGrayBitmap(unFocusImg_);
        }
    }

    /**
     * 根据xml重新修改控件对应的相关属性值
     * 
     * @param name
     */
    public void mouldCssStyleByName(String name , String value) {
    	if(null == name){
    		return;
    	}
        if (name.equalsIgnoreCase(CssStyle.BGIMAGEURL)) {
        	// 不支持 修改此样式的控件
        	if(this instanceof LPSegment || this instanceof LPSwitchCopy
        	        || this instanceof LPHtmlText || this instanceof LPLabel){
        	    return;
        	}
        	if (value.equals("")) {
        		// 如果服务端来的图片为空串,表示不需要图片显示
        		unFocusImg_ = null;
        		focusImg_ = null;
        		if (realView_ != null)
        		    realView_.setBackgroundColor(0);
        	} else {
        		// 根据样式定义控件选中图片
        		unFocusImg_ = Utils.getBitmapFromResources(getContext(), value);
        		if (null != unFocusImg_) {
        		    unFocusImg_ = Bitmap.createScaledBitmap(unFocusImg_, width_, height_, true);
        		}
        		// 用户点击的图片也应该有样式定义,此处暂时设置为未点击时的去色效果
        		focusImg_ = Utils.getGrayBitmap(unFocusImg_);
        		if(unFocusImg_ != null){
                    realView_.setBackgroundDrawable(new BitmapDrawable(unFocusImg_));
                }
        		// 对于按钮，重新设置其按下和抬起的背景图。
        		if(getTag() != null && "input".equalsIgnoreCase(getTag())
        				&& getPropertyByName("type") != null
        				&& ("button".equalsIgnoreCase(getPropertyByName("type")) || "submit".equalsIgnoreCase(getPropertyByName("type")))){
        			this.getButtonStatusBG();
        		}
            }
        } else if(name.equalsIgnoreCase(CssStyle.BACKGROUNDCOLOR)){
        	// 不支持修改背景色
        	if(this instanceof LPImageItem || this instanceof LPSegment || this instanceof LPSwitchCopy
        	        || this instanceof LPHtmlText || this instanceof LPLabel){
        	    return;
        	}
        	if (null != value && !value.equals("")) {
        		realView_.setBackgroundColor(Color.parseColor(value));
        	}
        }else if (name.equalsIgnoreCase(CssStyle.DISPLAY)) {
        	if (null != value && !value.equals("")) {
        		if (value.trim().equalsIgnoreCase("none")) {
        		    if(this instanceof LPSegment){
        		        if(parentComponent_ != null && parentComponent_.segmentLayout_ != null){
        		            parentComponent_.segmentLayout_.setVisible(View.GONE);
        		        } else {
        		            ((LPSegmentLayout)realView_.getParent()).setVisible(View.GONE);
        		        }
        		    } else {
        		        setVisible(View.GONE);
        		    }                    // 设置控件不可见后，需要重新布局一下界面上的相关元素
                    setComponentXYAgain();
                } else {
                	if(this instanceof LPSegment){
                		if(parentComponent_ != null && parentComponent_.segmentLayout_ != null){
                		    parentComponent_.segmentLayout_.setVisible(View.VISIBLE);
                		} else {
                		    ((LPSegmentLayout)realView_.getParent()).setVisible(View.VISIBLE);
                		}
                    } else {
                		setVisible(View.VISIBLE);
                    }
                    // 设置控件可见后，需要重新布局一下界面上的相关元素
                    setComponentXYAgain();
                }
            }
        } else if (name.equalsIgnoreCase(CssStyle.ENABLE)) {
        	if (null != value && !value.equals("")) {
        		if (value.equalsIgnoreCase("true")) {
                    setEnable(true);
                } else if (value.equalsIgnoreCase("false")) {
                    setEnable(false);
                }
            }
        } else if (name.equalsIgnoreCase(CssStyle.TOP) || name.equalsIgnoreCase(CssStyle.BOTTOM)) {
            Object o = cssStyle_.getProperty(name.toLowerCase());
            int top = 0;
            if (o instanceof Integer) {
                top = (Integer) o;
            } else if (o instanceof String) {
                if (o != null) {
                    String os = fixedPX(o.toString());
                    if (os.indexOf(".") != -1)
                        top = (int) Math.round(Double.parseDouble(os));
                    else
                        top = Integer.parseInt(os);
                }
            }
            if (o.toString().indexOf("px") != -1)
                cssStyle_.setProperty(name, Integer.toString(top).concat("px"));
            else
                cssStyle_.setProperty(name, Integer.toString(top));
            ViewGroup.LayoutParams groupParams = realView_.getLayoutParams();
            if(groupParams == null){
                return;
            }
            android.widget.AbsoluteLayout.LayoutParams lp = null;
            if(groupParams instanceof android.widget.AbsoluteLayout.LayoutParams){
                lp = (android.widget.AbsoluteLayout.LayoutParams)groupParams;
            } else {
                lp = (android.widget.AbsoluteLayout.LayoutParams)((ViewGroup)realView_.getParent()).getLayoutParams();
            }
            if (null == lp) {
                return;
            } else {
                top = Utils.getScaledValueY(top);
                // 判断是否是llv层的子控件,如果是还需减掉一个llv层的让渡值
//                LPLayout lpl = (LPLayout) getParent();
//                if ((null != lpl) && null != lpl.getTag() && lpl.getTag().equalsIgnoreCase("llv")) {
//                    top = top - lpl.llvTop_;
//                }
//                lp.y = top;
                lp.y = name.equalsIgnoreCase(CssStyle.TOP)? top: (getParent().height_ - lp.height - top);
            }
            if(groupParams instanceof android.widget.AbsoluteLayout.LayoutParams){
            	realView_.setLayoutParams(lp);
            } else {
            	((ViewGroup)realView_.getParent()).setLayoutParams(lp);
            }
            
            // 修改控件Top后，需要重新布局一下界面上的相关元素
            setComponentXYAgain();
        } else if (name.equalsIgnoreCase(CssStyle.HEIGHT)) {
            int height = 0;
            Object o = cssStyle_.getProperty(CssStyle.HEIGHT);
            if (o instanceof Integer) {
                height = (Integer) o;
            } else if (o instanceof String) {
                if (o != null) {
                    String os = fixedPX(o.toString());
                    if (os.indexOf(".") != -1)
                        height = (int) Math.round(Double.parseDouble(os));
                    else
                        height = Integer.parseInt(os);
                }
            }
            if (o.toString().indexOf("px") != -1)
                cssStyle_.setProperty(name, Integer.toString(height).concat("px"));
            else
                cssStyle_.setProperty(name, Integer.toString(height));
            ViewGroup.LayoutParams groupParams = realView_.getLayoutParams();
            if(groupParams == null){
                return;
            }
            boolean isAloneCom = true;
            android.widget.AbsoluteLayout.LayoutParams lp = null;
            if(groupParams instanceof android.widget.AbsoluteLayout.LayoutParams){
                lp = (android.widget.AbsoluteLayout.LayoutParams)groupParams;
            } else {
                lp = (android.widget.AbsoluteLayout.LayoutParams)((ViewGroup)realView_.getParent()).getLayoutParams();
                isAloneCom = false;
            }
            
            if (null == lp) {
                return;
            } else {
                height = Utils.getScaledValueY(height);
                lp.height = height;
                height_ = height;
                if(!isAloneCom){
                	//
                	ViewGroup parent = (ViewGroup)realView_.getParent();
                	for(int i = 0; i < parent.getChildCount() ; i++){
                	    Component component = getComponent(parent.getChildAt(i));
                	    component.unFocusImg_ = Bitmap.createScaledBitmap(component.unFocusImg_
                	            , width_, height_, true);
                	    component.focusImg_ = Bitmap.createScaledBitmap(component.focusImg_
                	            , width_, height_, true);
                	    component.getLayoutParams().height = height_;
                	    component.height_ = height_;
                	}
                } else if(this instanceof LPSwitchCopy){
                	((LPSwitchCopy)this).setSwitchIcons();
                } else if(this instanceof LPCheckBox){
                	((LPCheckBox)this).setCheckBoxIcons();
                } else if(this instanceof LPRadio){
                	((LPRadio)this).setRadioBoxIcons();
                } else if (null != unFocusImg_) {
                    // 控件大小被修改，相应的背景图片也应该被修改
                    unFocusImg_ = Bitmap.createScaledBitmap(unFocusImg_, width_, height_, true);
                    // 用户点击的图片也应该有样式定义,此处暂时设置为未点击时的去色效果
                    focusImg_ = Utils.getGrayBitmap(unFocusImg_);
                }
            }
            if(groupParams instanceof android.widget.AbsoluteLayout.LayoutParams){
            	realView_.setLayoutParams(lp);
            } else {
            	((ViewGroup)realView_.getParent()).setLayoutParams(lp);
            }
            realView_.invalidate();
            // 修改控件高度后，需要重新布局一下界面上的相关元素
            setComponentXYAgain();
        } else if (name.equalsIgnoreCase(CssStyle.LEFT) || name.equalsIgnoreCase(CssStyle.RIGHT)) {
            int temp = 0;
            Object o = cssStyle_.getProperty(name.toLowerCase());
            if (o instanceof Integer) {
                temp = (Integer) o;
            } else if (o instanceof String) {
                if (o != null) {
                    String os = fixedPX(o.toString());
                    if (os.indexOf(".") != -1)
                        temp = (int) Math.round(Double.parseDouble(os));
                    else
                        temp = Integer.parseInt(os);
                }
            }
            if (o.toString().indexOf("px") != -1)
                cssStyle_.setProperty(name, Integer.toString(temp).concat("px"));
            else
                cssStyle_.setProperty(name, Integer.toString(temp));
            ViewGroup.LayoutParams groupParams = realView_.getLayoutParams();
            if(groupParams == null){
                return;
            }
            android.widget.AbsoluteLayout.LayoutParams lp = null;
            if(groupParams instanceof android.widget.AbsoluteLayout.LayoutParams){
                lp = (android.widget.AbsoluteLayout.LayoutParams)groupParams;
            } else {
                lp = (android.widget.AbsoluteLayout.LayoutParams)((ViewGroup)realView_.getParent()).getLayoutParams();
            }
            
            if (null == lp) {
                return;
            } else {
                temp = Utils.getScaledValueX(temp);
                if(name.equalsIgnoreCase(CssStyle.LEFT)){
                    
                    lp.x = temp;
                } else {
                    
                    lp.x = getParent().width_ - lp.width - temp;
                }
            }
            if(groupParams instanceof android.widget.AbsoluteLayout.LayoutParams){
                realView_.setLayoutParams(lp);
            } else {
               ((ViewGroup)realView_.getParent()).setLayoutParams(lp);
            }
            
        } else if (name.equalsIgnoreCase(CssStyle.WIDTH)) {
            int temp = 0;
            Object o = cssStyle_.getProperty(CssStyle.WIDTH);
            if (o instanceof Integer) {
                temp = (Integer) o;
            } else if (o instanceof String) {
                if (o != null) {
                    String os = fixedPX(o.toString());
                    if (os.indexOf(".") != -1)
                        temp = (int) Math.round(Double.parseDouble(os));
                    else
                        temp = Integer.parseInt(os);
                }
            }
            if (o.toString().indexOf("px") != -1)
                cssStyle_.setProperty(name, Integer.toString(temp).concat("px"));
            else
                cssStyle_.setProperty(name, Integer.toString(temp));
            boolean isAloneCom = true;
            ViewGroup.LayoutParams groupParams = realView_.getLayoutParams();
            if(groupParams == null){
                return;
            }
            
            android.widget.AbsoluteLayout.LayoutParams lp = null;
            if(groupParams instanceof android.widget.AbsoluteLayout.LayoutParams){
                lp = (android.widget.AbsoluteLayout.LayoutParams)groupParams;
            } else {
                isAloneCom = false;
                lp = (android.widget.AbsoluteLayout.LayoutParams)((ViewGroup)realView_.getParent()).getLayoutParams();
            }
            if (null == lp) {
                return;
            } else {
                temp = Utils.getScaledValueX(temp);
                lp.width = temp;
                width_ = temp;
                if(!isAloneCom){
                	//
                	ViewGroup parent = (ViewGroup)realView_.getParent();
                	int childSize = parent.getChildCount();
                	for(int i = 0; i < childSize ; i++){
                	    Component component = getComponent(parent.getChildAt(i));
                	    component.unFocusImg_ = Bitmap.createScaledBitmap(component.unFocusImg_
                	            , width_ / childSize, height_, true);
                	    component.focusImg_ = Bitmap.createScaledBitmap(component.focusImg_
                	            , width_ / childSize, height_, true);
                	    component.getLayoutParams().width = width_ / childSize;
                	    component.width_ = width_ / childSize;
                	}
                } else if(this instanceof LPSwitchCopy){
                	((LPSwitchCopy)this).setSwitchIcons();
                } else if (null != unFocusImg_) {
                    // 控件大小被修改，相应的背景图片也应该被修改
                    unFocusImg_ = Bitmap.createScaledBitmap(unFocusImg_, width_, height_, true);
                    // 用户点击的图片也应该有样式定义,此处暂时设置为未点击时的去色效果
                    focusImg_ = Utils.getGrayBitmap(unFocusImg_);
                }
            }
            if(isAloneCom){
            	realView_.setLayoutParams(lp);
            } else {
            	((ViewGroup)realView_.getParent()).setLayoutParams(lp);
            }
            if(this instanceof LPLabel || this instanceof LPHtmlText){
            	reSetTextViewLayoutParams();
            }
        } else if (name.equalsIgnoreCase(CssStyle.FILTER)) {

            Object object = cssStyle_.getProperty(name);
            if (!(object instanceof String) || TextUtils.isEmpty((String) object)) {

                return;
            }
            
            setAlpha((String) object);
        } else if (name.equalsIgnoreCase(CssStyle.COLOR) || name.equalsIgnoreCase(CssStyle.FONTSIZE)
            || name.equalsIgnoreCase(CssStyle.FONTWEIGHT) || name.equalsIgnoreCase(CssStyle.TEXTALIGN)) {
            	moudFontCssStyleByName(name, value);
        }
    }
        
    /**
     * 修改控件 字体font-size、color、font-weight、text-align
     * */
    private void moudFontCssStyleByName(String name, String value){
        if(!"".equals(name)){
            if(value != null && !value.equals("")){
            	if(realView_ instanceof EditText){
            	    EditText et = (EditText)realView_;
            	    if(name.equalsIgnoreCase(CssStyle.TEXTALIGN)){
            	        if (value.equalsIgnoreCase("right")) {
            	            setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
            	        } else if(value.equalsIgnoreCase("left")){
            	            setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
            	        } else if (value.equalsIgnoreCase("center")) {
            	            setGravity(Gravity.CENTER);
            	        }
            	    } else if(name.equalsIgnoreCase(CssStyle.FONTWEIGHT)){
            	        setTypeFace((TextPaint) et.getPaint(), value);
            	    } else if(name.equalsIgnoreCase(CssStyle.FONTSIZE)){
            	        int fontSize = 0;
            	        fontSize = Integer.parseInt(fixedPX(value));
            	        fontSize = Utils.getFontSize(fontSize);
            	        if(fontSize > 0){
            	            et.setTextSize(fontSize);
            	        }
            	    } else if(name.equalsIgnoreCase(CssStyle.COLOR)){
            	        int color = Utils.getColorValue(value);
            	        et.setTextColor(color);
            	    }
            	} else if(realView_ instanceof CheckBox){
            	    CheckBox cb = (CheckBox)realView_;
            	    if(name.equalsIgnoreCase(CssStyle.FONTWEIGHT)){
            	        setTypeFace((TextPaint) cb.getPaint(), value);
            	    } else if(name.equalsIgnoreCase(CssStyle.FONTSIZE)){
            	        int fontSize = 0;
            	        fontSize = Integer.parseInt(fixedPX(value));
            	        fontSize = Utils.getFontSize(fontSize);
            	        if(fontSize > 0){
            	            cb.getPaint().setTextSize(fontSize);
            	        }
            	    } else if(name.equalsIgnoreCase(CssStyle.COLOR)){
            	        int color = Utils.getColorValue(value);
            	        cb.getPaint().setColor(color);
            	    }
            	} else if(realView_ instanceof RadioButton){
            	    RadioButton rb = (RadioButton)realView_;
            	    if(name.equalsIgnoreCase(CssStyle.FONTWEIGHT)){
            	        setTypeFace((TextPaint) rb.getPaint(), value);
            	    } else if(name.equalsIgnoreCase(CssStyle.FONTSIZE)){
            	        int fontSize = 0;
            	        fontSize = Integer.parseInt(fixedPX(value));
            	        fontSize = Utils.getFontSize(fontSize);
            	        if(fontSize > 0){
            	            rb.getPaint().setTextSize(fontSize);
            	        }
            	    } else if(name.equalsIgnoreCase(CssStyle.COLOR)){
            	        int color = Utils.getColorValue(value);
            	        rb.getPaint().setColor(color);
            	    }                
            	} else if(realView_ instanceof TextView){
            		TextView tv = (TextView)realView_;
            		if(name.equalsIgnoreCase(CssStyle.FONTWEIGHT)){
//            		    setTypeFace((TextPaint) tv.getPaint(), value);
            		    // em strong 不支持该属性设置
            		    if(!getTag().equalsIgnoreCase("strong") && !getTag().equalsIgnoreCase("em")){
            		        setTypeFace((TextPaint) tv.getPaint(), value);
            		    }
            		} else if(name.equalsIgnoreCase(CssStyle.FONTSIZE)){
            		    int fontSize = 0;
            		    fontSize = Integer.parseInt(fixedPX(value));
            		    fontSize = Utils.getFontSize(fontSize);
            		    if(fontSize > 0){
            		        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize);
            		        tv.getPaint().setTextSize(fontSize);
            		    }
            		} else if(name.equalsIgnoreCase(CssStyle.COLOR)){
            		    int color = Utils.getColorValue(value);
            		    tv.getPaint().setColor(color);
            		    tv.setTextColor(color);
            		}
            	}
            }
        }
    }
    
    /**
     * 设置View的alpha值，
     * @param alpha  接受如： “...alpha=0.5daf”类似值，
     */
    public void setAlpha(String alpha) {
        final String value = alpha.trim();
        int index = value.indexOf("alpha=");
        if (index >= 0) {
            final float digital = Utils.getDigital(value.substring(index));
            Animation animation = new Animation() {
                @Override
                protected void applyTransformation(float interpolatedTime, Transformation t) {
                    t.setAlpha(digital);
                }
            };
            animation.setFillAfter(true);
            realView_.startAnimation(animation);
        }
    }
    
    
    private int getCssStyleValue(String key) {

        final Object object = cssStyle_.getProperty(key.toLowerCase());
        if (null == object) {

            return Integer.MIN_VALUE;
        }

        int value = 0;
        if (object instanceof Integer) {

            value = (Integer) object;
        } else if (object instanceof String) {

            String os = fixedPX(object.toString());
            if (os.indexOf(".") != -1) {

                value = (int) Math.round(Double.parseDouble(os));
            } else {

                value = Integer.parseInt(os);
            }
        }

        if (object.toString().indexOf("px") != -1) {

            cssStyle_.setProperty(key, Integer.toString(value).concat("px"));
        } else {

            cssStyle_.setProperty(key, Integer.toString(value));
        }
        return Utils.getScaledValueY(value);
    }

    /**
     * 控件参与联动后,执行该方法重新布置界面上的相关布局 1.遍历该控件的父控件,寻找该控件后面的控件 2.遍历过程中,不可见控件不参加重新布局
     * 3.所有控件遍历完毕后,如果父控件大小改变,应该继续向上遍历父控件的父控件,并且逐一比较改变位置
     * 
     * @param component
     */
    public void setComponentXYAgain() {
        // TODO Auto-generated method stub
        LPLayout lpl = null;
        if (getParent() == null || !(getParent() instanceof LPLayout)) {
            return;
        } else {
            lpl = (LPLayout) getParent();
        }
        parent_ = lpl;
        // 先记录父级控件的原始高度，如有必要，需要和调整以后的高度作对比
        int lplHeight = lpl.hSelfMax_;
        // 获取该控件的前一个可见的位置
        Component temp;
        int index = parent_.indexOfChild(realView_);
        if (index == 0) {
            lpl.setXMax(0);
            lpl.setYMax(0);
            lpl.setYTop(0);
            lpl.setWMax(0);
            lpl.setHMax(0);
        } else {
            index = getVisibleIndex(lpl, this);
            if (index == -1) {
                lpl.setXMax(0);
                lpl.setYMax(0);
                lpl.setYTop(0);
                lpl.setWMax(0);
                lpl.setHMax(0);
            } else {
                temp = lpl.getChildAt(index);
                // android.widget.AbsoluteLayout.LayoutParams lp = (android.widget.AbsoluteLayout.LayoutParams) temp
                // .getLayoutParams();
                // 得到前一个控件后，将该控件纪录的XY值赋给父控件的相关参数

                lpl.setXMax(temp.xParentMax_);

                lpl.setYMax(temp.yParentMax_);

                // lpl.setXMax(lp.x + lp.width);
                // lpl.setYMax(lp.y + lp.height);
                if (temp instanceof LPLayout && ((LPLayout) temp).isNewLine_) {
                    lpl.setYTop(temp.yParentMax_);
                    // lpl.setYTop(lp.y + lp.height);
                } else {
                    lpl.setYTop(temp.yParentTop_);
                    // lpl.setYTop(lp.y);
                }
                lpl.setWMax(temp.wParentMax_);
                lpl.setHMax(temp.hParentMax_);
            }
        }
        
        int sum = lpl.getChildCount();
        try {
            int i;
            if (parent_.indexOfChild(realView_) == 0)
                // 如果联动的是父控件的第一个控件，则遍历父控件中所有的可见元素
                i = 0;
            else
                // 如果联动的不是父控件的第一个控件，则执行部分遍历操作
                i = index + 1;

            for (; i < sum; i++) {
                temp = lpl.getChildAt(i);
                //如果改控件是隐藏并且不是最后一个，就不作计算，否则控件联动时，高度计算不正确
                if (temp.getVisibility() == View.GONE && (i != sum-1))
                    continue;
                temp.adjustXY();
                // 检查该控件是否是其父控件的最后一个控件
                // 如果是最后一个控件则还应检查父控件的大小是否已经改变，如果已经改变，需继续调整父控件级的大小及其后控件的布局。
                if (i == sum - 1) {
                    if (lpl.getPropertyByName(CssStyle.HEIGHT).equals("")) {
                    	// 服务端也未指定父级控件的高度，说明该父级控件高度可改变
                    	if (lplHeight != lpl.hSelfMax_) {
                    		lpl.mouldW();
                    		lpl.setComponentXYAgain();
                    		lpl.mouldH();
                    	}
                    }
                }
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            Utils.printException(e);
        }
        lpl.checkChildLayoutInTR();
        lpl.checkChildLayout();
    }

    /**
     * 获取控件的前一个显示控件序号
     * 
     * @param component
     * @param component
     * @return 返回值有可能为-1,如果为-1表示前面所有控件都为不显示状态
     */
    private int getVisibleIndex(LPLayout parent, Component component) {
        // TODO Auto-generated method stub
        int i = parent.indexOfChild(component.realView_);
        if ((i - 1) < 0)
            return -1;
        Component temp = parent.getChildAt(i - 1);
        if (temp.getVisibility() == View.GONE) {
            // 如果前一个控件不可见则持续往上查找上查找
            return getVisibleIndex(parent, temp);
        } else {
            return (i - 1);
        }
    }

    public Context getContext() {
    	if(realView_ == null){
    		return null;
    	}
        return realView_.getContext();
    }

    public void setLayoutParams(final LayoutParams lp) {
        // TODO Auto-generated method stub
        if (null != realView_) {
            ((Activity) getContext()).runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    realView_.setLayoutParams(lp);
                }

            });

        }
    }

    protected void scrollBy(int scrollX, int scrollY) {
        realView_.scrollBy(scrollX, scrollY);
    }

    protected void scrollTo(int scrollX, int scrollY) {
        // TODO Auto-generated method stub
        realView_.scrollTo(scrollX, scrollY);
    }

    protected int getScrollX() {
        // TODO Auto-generated method stub
        return realView_.getScrollX();
    }

    protected int getScrollY() {
        // TODO Auto-generated method stub
        return realView_.getScrollY();
    }

    /*
     * ************************************************************************
     * Event methods. ************************************************************************
     */
    /**
     * @param event
     * @return
     */
    protected boolean pressedEvent(MotionEvent event) {
        return false;
    }

    /*
     * ************************************************************************
     * Set and Get the attributes from XHTML & XML documents.
     * ************************************************************************
     */
    /**
     * @param key
     * @return
     */
    public String getAttribute(String key) {
        if (attributes_ == null) {
            return null;
        }
        return attributes_.get(key);
    }

    /**
     * Set the attributes from XML documents.
     * 
     * @param key
     * @param value
     */
    public void setAttribute(String key, String value) {
        if (attributes_ == null) {
            attributes_ = new HashMap<String, String>();
        }
        attributes_.put(key, value);
    }

    /**
     * @return
     */
    public String name() {
        return getAttribute(ATTRIBUTE_NAME);
    }

    /**
     * @param name
     */
    public void setName(String name) {
        setAttribute(ATTRIBUTE_NAME, name);

    }

    /**
     * @return
     */
    public String inputType() {
        return getAttribute(ATTRIBUTE_INPUT_TYPE);
    }

    /**
     * @param type
     */
    public void setInputType(String type) {
        setAttribute(ATTRIBUTE_INPUT_TYPE, type);
    }

    /**
     * @return
     */
    int styleIndex() {
        if (attributes_ == null) {
            return DEFAULT_STYLE_INDEX;
        }
        String sindex = null;
        sindex = getAttribute(ATTRIBUTE_STYLE_INDEX);
        if (sindex == null) {
            return DEFAULT_STYLE_INDEX;
        }
        try {
            int index = -1;
            index = Integer.parseInt(sindex);
            if (index < 0) {
                index = DEFAULT_STYLE_INDEX;
            }
            return index;
        } catch (Exception e) {
            return DEFAULT_STYLE_INDEX;
        }
    }

    public void removeView(Component component) {
    }

    /**
     * @param styleIndex
     */
    public void setStyleIndex(int styleIndex) {
        String sindex = String.valueOf(styleIndex);
        setAttribute(ATTRIBUTE_STYLE_INDEX, sindex);
    }

    /**
     * 给控件一个标志位
     * 
     * @param name
     */
    public void setTag(String name) {
        if (null != realView_)
            realView_.setTag(name);
    }

    /**
     * @param text
     */
    public void setContentText(String text) {
        setAttribute(ATTRIBUTE_CONTENT_TEXT, text);
    }

    /**
     * @return
     */
    private String label() {
        return getAttribute(ATTRIBUTE_LABEL);
    }

    /**
     * @return
     */
    public String accessory() {
        return getAttribute(ATTRIBUTE_ACCESSORY);
    }

    /**
     * 设置该控件前面br的高度
     * 
     * @param h
     */
    public void setBrHeight(int h) {
        brHeight_ = h;
    }

    public int getBrHeight() {
        return brHeight_;
    }

    /**
     * @param accessory
     */
    public void setAccessory(String accessory) {
        setAttribute(ATTRIBUTE_ACCESSORY, accessory);
    }

    /**
     * @return
     */
    public boolean required() {
        String require = getAttribute(ATTRIBUTE_REQUIRED);
        boolean b = false;
        try {
            b = Boolean.parseBoolean(require);
        } catch (Exception e) {
        }
        return b;
    }

    /**
     * @param required
     */
    public void setRequired(boolean required) {
        String strRequired = String.valueOf(required);
        setAttribute(ATTRIBUTE_REQUIRED, strRequired);
    }

    /**
     * @return
     */
    public String src() {
        return getAttribute(ATTRIBUTE_SRC);
    }

    /**
     * @return
     */
    public int bgColor() {
        int color = 0xFFFFFFFF;
        if (null != cssStyle_ && null != cssStyle_.getProperty(CssStyle.BACKGROUNDCOLOR)) {
            color = Utils.getColorValue((String) cssStyle_.getProperty(CssStyle.BACKGROUNDCOLOR));
        }

        return color;
    }

    /**
     * @return
     */
    public int fgColor() {
        int color = 0xFFFFFFFF;
        if (null != cssStyle_ && null != cssStyle_.getProperty(CssStyle.COLOR)) {
            color = Utils.getColorValue((String) cssStyle_.getProperty(CssStyle.COLOR));
        }
        return color;
    }

    /**
     * @param color
     */
    public void setBorderColor(int color) {
        if (cssStyle_ == null) {
            cssStyle_ = new CssStyle();
        }
        cssStyle_.borderColor_ = color;
    }

    /**
     * @return
     */
    public int borderColor() {
        if (cssStyle_ == null) {
            return 0;
        }
        return cssStyle_.borderColor_;
    }

    /**
     * 判断并绘制边界 该方法一般都在绘制方法的最后调用
     * 
     * @param canvas
     */
    void drawBorder(Canvas canvas) {
        if (cssStyle_ != null) {
            String temp = (String) cssStyle_.getProperty(CssStyle.BGIMAGEURL);
            if (null != temp && !temp.equals("")) {
                // 如果指定背景图片则不进行边框的绘制操作
                return;
            }
        }
        // 边线宽度
        int border_width = -1;
        String bw = (String) getPropertyByName("border");
        if (getTag() != null 
        		&& ("tr".equalsIgnoreCase(getTag()) || "th".equalsIgnoreCase(getTag()) || "td".equalsIgnoreCase(getTag()))) {
            bw = "";
        }
        if (!bw.equals("")) {
            bw = fixedPX(bw);
            border_width = Integer.parseInt(bw);
        }
        // 优先样式设置
        if (null != cssStyle_) {
            border_width = (cssStyle_.borderWidth_ > 0) ? cssStyle_.borderWidth_ : border_width;
        }
        if (border_width > 0) {
            drawBorderAndBg(canvas, border_width);
        } else if (border_width < 0) {
            // table和div默认的效果为圆角带边框
            if (null != getTag() && (getTag().equalsIgnoreCase("table") || getTag().equalsIgnoreCase("div")))
                drawBorderAndBg(canvas, border_width);
            else{
            	// 如果是tr标签，但是没有拿到border属性，那么就不绘制边框线。
            	if(getTag() != null && getTag().equalsIgnoreCase("tr")){
            		// tr没有指定样式，不绘制边框线。
            		if(cssStyle_ == null){}
            		// tr的样式中没有关于border的设置，也不绘制边框线。
            		else if(cssStyle_ != null 
            				&& (getPropertyByName("border") == null) 
            				|| "".equalsIgnoreCase(getPropertyByName("border"))){}
            		else{
            			drawRectBorder(canvas, border_width);
            		}
            	} 
            	// 若是td标签，但也没有指定border属性，那么也不绘制边框线。
            	else if(getTag() != null && getTag().equalsIgnoreCase("td")){
            		// td没有指定样式，不绘制边框线。
            		if(cssStyle_ == null){}
            		// td的样式中没有关于边框线的设置，也不绘制边框线。
            		else if(cssStyle_ != null
            				&& (getPropertyByName("border") == null) 
            				|| "".equalsIgnoreCase(getPropertyByName("border"))){}
            		else{
            			drawRectBorder(canvas, border_width);
            		}
            	} else {
            		drawRectBorder(canvas, border_width);
            	}
            }
        }
    }

    /**
     * 绘制直角矩形背景
     * 
     * @param canvas
     * @param border_width
     */
    private void drawRectBorder(Canvas canvas, int border_width) {
        String frame = "";
        if (null != attributes_)
            frame = attributes_.get("BackgroundColor_");
        int bgColor = Color.TRANSPARENT;
        if (null != frame && !frame.equals(""))
            bgColor = Color.parseColor(frame);
        if (cssStyle_ != null) {
            String temp = (String) cssStyle_.getProperty(CssStyle.BACKGROUNDCOLOR);
            if (null != temp && !temp.equals("")) {
                bgColor = Color.parseColor(temp);
            }
        }
        Rect rect = new Rect(0, 0, getWidth(), getHeight());
        if (paint_ == null) {
            paint_ = new Paint();
        }
        paint_.setAntiAlias(true);
        paint_.setColor(bgColor);
        paint_.setStyle(Style.STROKE);
        canvas.drawRect(rect, paint_);
    }

    /**
     * 绘制圆角矩形和边线
     * 
     * @param canvas
     */
    private void drawBorderAndBg(Canvas canvas, int border_width) {
        RectF f = new RectF(0, 0, getWidth(), getHeight());
        if (paint_ == null) {
            paint_ = new Paint();
            paint_.setAntiAlias(true);
        }
        String frame = "";
        if(attributes_ != null){
            frame = attributes_.get("BackgroundColor_");
        }
        int bgColor = 0x00000000;
        if (frame != null && !frame.equals(""))
            bgColor = Color.parseColor(frame);
        int border_color = Color.BLACK;// 灰色
        int RADIUS = LPLayout.TABLE_BG_RADIOUS_;
        if (cssStyle_ != null) {
            String temp = (String) cssStyle_.getProperty(CssStyle.BACKGROUNDCOLOR);
            if (null != temp && !temp.equals("")) {
                bgColor = Color.parseColor(temp);
            }
            if (cssStyle_.borderColor_ != 0) {
                border_color = cssStyle_.borderColor_;
            }
            
        }
        // 如果属性中说border为0，那么表格的边框线为直角。
        if(getTag() != null && getTag().equalsIgnoreCase("table")
        		&& getPropertyByName("border") != null && getPropertyByName("border").equals("0")){
        	RADIUS = 0;
        }
        // 样式为空，或没有指定背景色及背景图
        if (cssStyle() == null || bgColor != 0
                && (cssStyle().content_ == null || (cssStyle().content_.indexOf(CssStyle.BGIMAGEURL) == -1 && cssStyle().content_
                        .indexOf(CssStyle.BACKGROUNDCOLOR) == -1))) {
            paint_.setColor(bgColor);
            paint_.setStyle(Style.FILL);
            canvas.drawRoundRect(f, RADIUS, RADIUS, paint_); // 画背景图，不带边线。
        } else if (bgColor != 0
                && null != cssStyle().content_
                && (cssStyle().content_.indexOf(CssStyle.BGIMAGEURL) < cssStyle().content_
                        .indexOf(CssStyle.BACKGROUNDCOLOR))) {
            // 背景图片指定在背景色之前，背景色设置才有效
            paint_.setColor(bgColor);
            paint_.setStyle(Style.FILL);
            canvas.drawRoundRect(f, RADIUS, RADIUS, paint_); // 画背景图，不带边线。
        }
        paint_.setStyle(Style.STROKE);
        paint_.setColor(border_color);
        paint_.setStrokeWidth(border_width);
        canvas.drawRoundRect(f, RADIUS, RADIUS, paint_); // 画边线。
    }

    public void setAnimation(Animation anim) {
        if (null != realView_)
            realView_.setAnimation(anim);
    }

    public void setBackgroundDrawable(Drawable drawable) {
        if (null != realView_)
            realView_.setBackgroundDrawable(drawable);
    }
    
    /**
     * 根据CssStyle 里background-image 设置背景图
     * */
    public void setBackgroundDrawableByCssStyle(){
        if(null != realView_ && null != cssStyle_){
            String bgImageUrl = cssStyle_.getProperty(CssStyle.BGIMAGEURL);
            if (null != bgImageUrl && !bgImageUrl.equals("")) {
                Bitmap bg = Utils.getBitmapFromResources(getContext(), bgImageUrl);
                if(null != bg){
                	unFocusImg_ = bg;
                    realView_.setBackgroundDrawable(new BitmapDrawable(bg));
                }
            }
        }
    }

    /** 
     * 设置背景颜色
     * params #RRGGBB 
     * */
    public void setBackgroundColorByCssStyle(){
    	if(null != realView_ && null != cssStyle_){
    	    String bgColor = cssStyle_.getProperty(CssStyle.BACKGROUNDCOLOR);
    		if (null != bgColor && !bgColor.equals("")) {
                int color = Color.parseColor(bgColor);
                realView_.setBackgroundColor(color);
            }
    	}
    }

    /*
     * ************************************************************************
     * Set and Get methods. ************************************************************************
     */

    /**
     * @param cssStyle
     *            the cssStyle_ to set
     */
    public void setCssStyle(CssStyle cssStyle) {
        cssStyle_ = cssStyle;
    }

    /**
     * @return the cssStyle_
     */
    public CssStyle cssStyle() {
        return cssStyle_;
    }

    /**
     * @param isFocusable
     */
    public void setFocusable(boolean isFocusable) {
        focusable_ = isFocusable;
        if (realView_ != null) {
            realView_.setFocusable(isFocusable);
            realView_.setFocusableInTouchMode(isFocusable);
        }
    }

    /**
     * @return
     */
    public boolean focusable() {
        return focusable_;
    }

    /**
     * NOTE: this should NOT be invoked by View.onFocusChanged().
     * 
     * @param isFocus
     */
    public void setFocus(boolean isFocus) {
    	if(realView_ != null){
    		if (isFocus) {
    		    realView_.requestFocus();
    		} else {
    		    realView_.clearFocus();
    		}
        }
    }

    /**
     * @return
     */
    public boolean isFocused() {
        boolean focused = false;
        if (realView_ != null) {
            focused = realView_.isFocused();
        }
        return focused;
    }

    /**
     * @param visible
     */
    public void setVisible(final int visible) {
        visiable_ = visible;
        if (realView_ != null) {
        	if (cssStyle_ == null || null == cssStyle_.getProperty(CssStyle.FILTER)) {
        	    ((Activity) getContext()).runOnUiThread(new Runnable() {
        	        @Override
        	        public void run() {
        	            realView_.setVisibility(visible);
        	        }
        	    });
        	} else {
        	    if (View.GONE == visible || View.INVISIBLE == visible) {
        	        setAlpha("alpha=0");
        	    } else {
        	    	mouldCssStyleByName(CssStyle.FILTER , cssStyle_.getProperty(CssStyle.FILTER));
                }
            }
        }
    }

    /**
     * @return
     */
    public int visible() {
        return visiable_;
    }

    /**
     * @param isEncrypt
     *            the isEncrypt_ to set
     */
    public void setEncrypt(boolean isEncrypt) {
        isEncrypt_ = isEncrypt;
    }

    /**
     * @return the isEncrypt_
     */
    public boolean isEncrypt() {
        return isEncrypt_;
    }

    /**
     * @param focusableInTouchMode
     *            the focusableInTouchMode_ to set
     */
    public void setFocusableInTouchMode(boolean focusableInTouchMode) {
        focusableInTouchMode_ = focusableInTouchMode;
        if (realView_ != null) {
            realView_.setFocusableInTouchMode(focusableInTouchMode);
        }
    }

    /**
     * @return the focusableInTouchModel_
     */
    public boolean isFocusableInTouchMode() {
        return focusableInTouchMode_;
    }

    /**
     * @param relaEnable_
     *            the relaEnable_ to set
     */
    public void setRelaEnable(String[] relaEnable_) {
        this.relaEnable_ = relaEnable_;
    }

    /**
     * @return the relaEnable_
     */
    public String[] relaEnable() {
        return relaEnable_;
    }

    /**
     * @param relaDisable_
     *            the relaDisable_ to set
     */
    public void setRelaDisable(String[] relaDisable_) {
        this.relaDisable_ = relaDisable_;
    }

    /**
     * @return the relaDisable_
     */
    public String[] relaDisable() {
        return relaDisable_;
    }

    /**
     * @param relaVisible_
     *            the relaVisible_ to set
     */
    public void setRelaVisible(String[] relaVisible_) {
        this.relaVisible_ = relaVisible_;
    }

    /**
     * @return the relaVisible_
     */
    public String[] relaVisible() {
        return relaVisible_;
    }

    /**
     * @param relaInvisible_
     *            the relaInvisible_ to set
     */
    public void setRelaInvisible(String[] relaInvisible_) {
        this.relaInvisible_ = relaInvisible_;
    }

    /**
     * @return the relaInvisible_
     */
    public String[] relaInvisible() {
        return relaInvisible_;
    }

    public void onTouchEvent(MotionEvent event) {
        if (null != realView_){
        	realView_.onTouchEvent(event);
        }
    }

    public void startAnimation(Animation animation) {
        if (null != realView_)
            realView_.startAnimation(animation);
    }

    protected boolean onClick(String methodName) {
        if (!isEnable()) {
            return true;
        }
        if (methodName == null || methodName.equals("")) {
            // 如果自己的点击调用不存在，则将该点击效果往父系控件传递，直到存在点击事件，或无父系控件可传
            // 用该递归调用方法来解决tr控件的点击问题
            Component c = null;
            c = getParent();
            if (null != c)
                c.onClick((String) c.getPropertyByName("onclick"));
        } else {
            // 不能太频繁的调gc，点击事件更不需要gc.
            // Component.LUASTATE.gc(LuaState.LUA_GCCOLLECT, 0);
            int index = Component.LUASTATE.LdoString(methodName);
            if (index > 0) {
                Utils.printOutToConsole("Lua Text has some errors:");
                Utils.printOutToConsole(Component.LUASTATE.LcheckString(-1));
            }
        }
        return true;
    }

    /**
     * @param enabled
     *            the isEnable_ to set
     */
    public void setEnable(boolean enabled) {
        isEnable_ = enabled;
        if (realView_ != null) {
            realView_.setEnabled(enabled);
        }
    }

    /**
     * @return the isEnable_
     */
    public boolean isEnable() {
        return isEnable_;
    }

    /**
     * @param context
     * @param resourceId
     * @return
     */
    public static Bitmap[] createImg(Context context, String resourceId) {
        Bitmap[] buttonImg = new Bitmap[3];
        Bitmap buttonAllImg = null;
        buttonAllImg = ImageRepository.getImageFromAssetFile(context, resourceId);
        if (buttonAllImg == null) {
            return null;
        }
        int width = buttonAllImg.getWidth() / 3;
        int height = buttonAllImg.getHeight();
        buttonImg[NORMAL_IMG] = Bitmap.createBitmap(buttonAllImg, 0, 0, width, height);
        buttonImg[FOCUS_IMG] = Bitmap.createBitmap(buttonAllImg, width, 0, width, height);
        buttonImg[DOWN_IMG] = Bitmap.createBitmap(buttonAllImg, width * 2, 0, width, height);
        if (buttonAllImg != null && !buttonAllImg.isRecycled()) {
            buttonAllImg.recycle();
        }
        buttonAllImg = null;
        return buttonImg;
    }

    /**
     * 与上层控件断绝父子关系。
     */
    public void disinheritance() {
        ViewGroup vg = (ViewGroup) realView_.getParent();
        if (null != vg) {
            vg.removeView(realView_);
//            vg = null;
        }
    }

    public void setId(int o) {
        if (null != realView_)
            realView_.setId(o);
    }

    /**
     * 根据给的参数获取该控件对应的外部类对象
     * 
     * @param v
     * @return
     */
    public Component getComponent(Object v) {
        // TODO Auto-generated method stub
        if (v instanceof CompositedComponent) {
            CompositedComponent cc = (CompositedComponent) v;
            return cc.composited();
        }
        return null;
    }

    public void releaseResource(Component component) {
        Component.VWIDGETARRAY.remove(this);
        View view = component.realView_;
        if (view instanceof ViewGroup) {
            ViewGroup ll = (ViewGroup) view;
            final int size = ll.getChildCount();
            View v = null;
            for (int i = 0; i < size; i++) {
                v = ll.getChildAt(i);
                Component c = (Component) getComponent(v);
				if(null != c){
					c.releaseResource(c);
				} else {
					// 如果发现子元素是横向滚动视图，那么就释放掉其子元素的资源。
					if(v instanceof HSView){
						HSView hsView = (HSView) v;
						hsView.releaseResource();
					}
				}
                c = null;
            }
        }

        if (null != focusImg_ && !focusImg_.isRecycled()) {
            focusImg_.recycle();
        }
        focusImg_ = null;

        if (null != unFocusImg_ && !unFocusImg_.isRecycled()) {
            unFocusImg_.recycle();
        }
        unFocusImg_ = null;

        if (null != property_)
            property_.clear();
        property_ = null;
        parent_ = null;
        parentComponent_ = null;
        attributes_ = null;
        realView_ = null;
    }

    boolean dealWithLink(String link, Activity bv) {
        try {
            dialWeb(link, bv);
            return true;
        } catch (Exception ex) {
            Utils.printException(ex);
        }
        return false;
    }

    void dialWeb(String url, Activity bv) throws Exception {
        if (url.endsWith(".apk")) {
            WaitDialog wd = new WaitDialog();
            wd.showProgressdialog(bv);
            getUpdateFile(url, bv);
        } else if (url.startsWith("local://")) {
            String fileName = url.replace("local://", "");
            showLocalContent(fileName, bv); 
        } else {
            if (!url.startsWith("http://") && url.indexOf("//") != -1) {
                url = url.replace("//", "");
            }
            
            bv.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
        }
    }
        
    private void showLocalContent(String file, final Activity bv) {
    	String content = Utils.readLocalFileForStr(file);
    	if(!TextUtils.isEmpty(content)){
    	    
    	    content = Utils.unescapeHTML(content);
    	    content = Utils.insteadOfSpecillCharacter(content, true);
    	    AtomParser apc = null;
    	    if (content.contains("body"))
    	        apc = new AtomParser(bv, AtomParser.ENTIRE);
    	    else
    	        apc = new AtomParser(bv, AtomParser.PARTLY);
    	
    	    try {
    	        android.util.Xml.parse(content.trim(), apc);
    	        bv.runOnUiThread(new Runnable() {
    	
    	            @Override
    	            public void run() {
    	                // TODO Auto-generated method stub
    	                bv.setContentView(ComponentCopy.COMPONENT.getLPView());
    	            }
    	
    	        });
    	
    	    } catch (SAXException e) {
    	        // TODO Auto-generated catch block
    	        Utils.printException(e);
    	    }
        }
    }

    private void getUpdateFile(final String string, final Activity bv) {
        // TODO Auto-generated method stub
        try {
            Runnable r = new Runnable() {

                public void run() {
                    // TODO Auto-generated method stub
                    try {
                        getDataSource(string, bv);
                        System.exit(0);
                    } catch (Exception e) {
                        Utils.printException(e);
                    }
                }

            };
            new Thread(r).start();
        } catch (Exception e) {
            Utils.printException(e);
        }
    }

    private void getDataSource(String strPath, Activity bv) throws IOException {
        // TODO Auto-generated method stub
        // 取得URL
        URL urlTemp = new URL(strPath);
        // 创建连接
        URLConnection conn = urlTemp.openConnection();
        conn.connect();
        // 下载文件
        InputStream is = conn.getInputStream();
        if (null == is) {
            throw new RuntimeException("stream is null");
        }
        // 创建临时文件
        File fileTemp = File.createTempFile("update", ".apk");
        // 取得临时文件路径
        String currentTempFilePath = fileTemp.getAbsolutePath();
        // 将文件写入暂存盘
        FileOutputStream fos = new FileOutputStream(fileTemp);
        byte buf[] = new byte[128];
        do {
            int numread = is.read(buf);
            if (numread <= 0) {
                break;
            }
            fos.write(buf, 0, numread);
        } while (true);
        // 打开文件进行安装
        openFile(fileTemp, bv);
        try {
            is.close();
        } catch (Exception e) {
            Utils.printException(e);
        }
    }

    private void openFile(File fileTemp, Activity bv) {
        // TODO Auto-generated method stub
        Intent intent = new Intent();
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setAction(android.content.Intent.ACTION_VIEW);
        String type = getMIMEType(fileTemp);
        intent.setDataAndType(Uri.fromFile(fileTemp), type);
        bv.startActivity(intent);
    }

    private String getMIMEType(File fileTemp) {
        // TODO Auto-generated method stub
        String type = "";
        String fName = fileTemp.getName();
        String end = fName.substring(fName.lastIndexOf(".") + 1, fName.length()).toLowerCase();
        if (end.equals("m4a") || end.equals("mp3") || end.equals("mid") || end.equals("xmf") || end.equals("ogg")
                || end.equals("wav")) {
            type = "audio";
        } else if (end.equals("3gp") || end.equals("mp4")) {
            type = "video";
        } else if (end.equals("jpg") || end.equals("gif") || end.equals("png") || end.equals("jpeg")
                || end.equals("bmp")) {
            type = "image";
        } else if (end.equals("apk")) {
            type = "application/vnd.android.package-archive";
        } else {
            type = "*";
        }
        if (end.equals("apk")) {

        } else {
            type += "/*";
        }
        return type;
    }

    public Component getParent() {
    	Component component = null;
        if (null != realView_) {
        	component = getComponent(realView_.getParent());
        	if (null != parentComponent_) {
        		component = parentComponent_;
        	}
        }
        return component;
    }

    public void setHref(String name) {
        attrHref_ = name;
    }

    public void setMaxLeng(String name) {
        if (null != name && !name.equals(""))
            maxSize_ = Integer.parseInt(name);
        else
            maxSize_ = 0;
    }

    public void setMinLeng(String name) {
        if (null != name && !name.equals(""))
            minSize_ = Integer.parseInt(name);
        else
            minSize_ = 0;
    }

    public void setAttrValue(String name) {
        attrValue_ = name;
    }

    public void setStyle(String name) {
        attrStyle_ = name;
    }

    public void setEncrypt(String name) {

    }

    public void setDelay(String name) {
        if (null != name && !name.equals(""))
            delaytime_ = Integer.parseInt(name);
        else
            delaytime_ = 0;
    }

    public void setNodeName(String name) {
        nodeName_ = name;
    }

    public String getTag() {
        if (null == realView_)
            return "";
        return (String) (realView_.getTag() == null ? "" : realView_.getTag());
    }

    public String getPropertyByName(String key) {
        if (null == property_)
            return "";
        // 所有的属性必须为小写
//        if (key != null) {
//            key = key.toString().toLowerCase();
//        }
        String value = property_.get(key);
//        if (key != null && key.equals("value") && (value == null || value.equals(""))) {
//            String text = property_.get("text");
//            return text == null ? "" : text;
//        } else {
            return value == null ? "" : value;
//        }
    }

    public void setPropertyByName(Object key, Object value) {
        if (null == property_)
            property_ = new HashMap<String, String>();
        // 所有的属性必须是英文小写
        if (key != null) {
        	key = key.toString().trim().toLowerCase();
        	value = value != null ? value.toString().trim() : "";
        	// 如果是tagname标签
        	if (key.toString().equalsIgnoreCase("tagname")) {
        	    if (property_.get(key) != null && !property_.get(key).equals("")) {
        	        // tagName 标签名称 不可更改
        	        new AlertDialog.Builder((Activity) getContext()).setTitle("提示").setMessage("tagName标签不可更改")
        	                .setCancelable(true).setNegativeButton("确定", new DialogInterface.OnClickListener() {
        	                    public void onClick(DialogInterface dialog, int which) {
        	                    }
        	                }).show();
        	        return;
        	    }
        	}
        	
        	if(this instanceof LPSegment && (key.toString().equals("name") || key.toString().equals("value") 
        	        || key.toString().equals("text"))){
        	    ((LPSegment)this).setPropertyByNameToCheckedItem(key.toString(), value.toString());
        	} else {
        	    property_.put(key.toString(), value.toString());
        	    
        	    if (null == realView_)
        	        return;
        	    // 在UI线程中进行属性设置。
        	    final String keyString = key.toString();
        	    final String valueString = value.toString();
        	    try{
        	    	if (Thread.currentThread().getId() == 1) {
        	    		mouldPropertyByName(key.toString(), value.toString());
        	    		
                    } else {
                        getActivity().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                            	mouldPropertyByName(keyString, valueString);
                            }
                        });
                    }
        	    } catch (Exception e){
        	    	Utils.printException(e);
        	    }
        	}
        	postInvalidate();
        }
    }

    /**
     * 修改控件属性效果
     * 
     * @param key
     * @param value2
     */
    private void mouldPropertyByName(final String key, final String value) {
    	if(null == key){
    	    return ;
    	}
    	if(key.equalsIgnoreCase(CssStyle.BGIMAGEURL)){
    		//以下控件不支持 通过属性设置该值
    		if(this instanceof LPImageItem || this instanceof LPSegment || this instanceof LPSwitchCopy
    		        || this instanceof LPHtmlText || this instanceof LPLabel || getTag().equalsIgnoreCase("form")){
    		    return;
    		}
    		if(cssStyle_ != null){
    			cssStyle_.setProperty(CssStyle.BGIMAGEURL, value);
    		}
    	    Bitmap bg = Utils.getBitmapFromResources(getContext(), value);
    	    if(null != bg){
    	        realView_.setBackgroundDrawable(new BitmapDrawable(bg));
    	    }
    	} else if (key.equals("enable")) {
    	    //以下控件不支持 通过属性设置该值
    	    if(getTag().equals("from") || this instanceof LPLabel){
    	        return;
    	    }
            String valuestr = (value == null ? "" : value);
            if (valuestr.equalsIgnoreCase("true")) {
            	if(this instanceof LPSegment){
            		if(parentComponent_ != null && parentComponent_.segmentLayout_ != null){
            		    parentComponent_.segmentLayout_.setEnable(true);
            		} else {
            		    ((LPSegmentLayout)realView_.getParent()).setEnable(true);
            		}
            	} else {
            		setEnable(true);
            	}
            } else if (valuestr.equalsIgnoreCase("false")) {
            	if(this instanceof LPSegment){
            		if(parentComponent_ != null && parentComponent_.segmentLayout_ != null){
            		    parentComponent_.segmentLayout_.setEnable(false);
            		} else {
            		    ((LPSegmentLayout)realView_.getParent()).setEnable(false);
            		}
            	} else {
            		setEnable(false);
            	}
            }
        } else if(key.equals("focus")){
        	//当前控件是否获取焦点 、目前只有 密码框、 输入框(均继承 EditText)；segment\switch\checkbox\radio支持此属性设置
        	  String valuestr = (value == null ? "" : value);
        	  
        	  if(valuestr.equalsIgnoreCase("true")){
        	      if(realView_ instanceof RadioButton || realView_ instanceof CheckBox 
        	    		  || realView_ instanceof EditText){                  
        	    	  setFocus(true);
                      if(realView_ instanceof EditText){
                	      EditText et = (EditText)realView_;
                	      String text = et.getText() == null ? "" : et.getText().toString();
                	      et.setSelection(text.length());//设置光标的在最后
                	  }
                  }
              } else if(valuestr.equalsIgnoreCase("false")){
                  if(realView_ instanceof RadioButton || realView_ instanceof CheckBox 
                	  || realView_ instanceof EditText){                  
                	  setFocus(false);
                  }            
              }
        } else if(key.equalsIgnoreCase("hold")) {
            //目前只有 密码框、 输入框(均继承 EditText)支持此属性设置
            if(realView_ instanceof EditText){               
            	getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                    	String text = getPropertyByName(key);
                    	EditText et = (EditText) realView_;
                    	if (!text.equalsIgnoreCase(et.getText().toString())) {
                    	    et.setHint(text);                        
                    	}
                    }
                });
            }
        } else if (key.equals("hide")) {
            //以下控件不支持 通过属性设置该值
            if(getTag().equals("td") || getTag().equals("th")){                
            	return;
            }
            if (null != value && !value.equals("")) {
            	if (value.equalsIgnoreCase("false")) {
            	    if(this instanceof LPSegment){
            	        if(parentComponent_ != null && parentComponent_.segmentLayout_ != null){
            	            parentComponent_.segmentLayout_.setVisible(View.VISIBLE);
            	        } else {
            	            ((LPSegmentLayout)realView_.getParent()).setVisible(View.VISIBLE);
            	        }
            	    } else {
            	        setVisible(View.VISIBLE);
            	    }
            	    // 设置控件不可见后，需要重新布局一下界面上的相关元素
             //                    setComponentXYAgain();
            	} else if (value.equalsIgnoreCase("true")) {
            	    if(this instanceof LPSegment){
            	        if(parentComponent_ != null && parentComponent_.segmentLayout_ != null){
            	            parentComponent_.segmentLayout_.setVisible(View.GONE);
            	        } else {
            	            ((LPSegmentLayout)realView_.getParent()).setVisible(View.GONE);
            	        }
            	    } else {
            	        setVisible(View.GONE);
            	    }
            	    // 设置控件可见后，需要重新布局一下界面上的相关元素
            	//                    setComponentXYAgain();
            	}
            }
        } else if(key.equals("src")){
            //只有 img 支持src属性设置
            if(this instanceof LPImageItem){
            	LPImageItem img = (LPImageItem)this;
            	img.getImgFromSRC();
            }
        } else if(key.equalsIgnoreCase("value")){
            if(realView_ instanceof TextView){
            	if(this instanceof LPSelect){
            	    return;
            	}
            	if(this instanceof LPButton || this instanceof LPLabel || this instanceof LPHtmlText){
            	    property_.put("text", value.toString());
            	}
            	final TextView tv = (TextView) realView_;
            	final Component com = this;
            	if (!value.equalsIgnoreCase(tv.getText().toString())) {
            	    getActivity().runOnUiThread(new Runnable() {
            	        @Override
            	        public void run() {
            	        	if(com instanceof LPLabel){
            	        		LPLabel lpl = (LPLabel)com;
            	        		//有lua重置label值时，将pos_置空，否则pos_是改变值之前的，会导致越界问题出现
            	        		lpl.pos_ = null;
            	        	}
            	        	tv.setText(value);
            	            if(com instanceof LPLabel || com instanceof LPHtmlText){
            	                reSetTextViewLayoutParams();
            	            }
            	        }
            	    });
            	}
            }
        } else if(key.equalsIgnoreCase("text")){
            if(realView_ instanceof TextView){
            	if(realView_ instanceof EditText || this instanceof LPSelect){
            	    return;
            	}
            	if(this instanceof LPButton || this instanceof LPLabel || this instanceof LPHtmlText){
            	    property_.put("value", value.toString());
            	}
            	final Component com = this;                
            	getActivity().runOnUiThread(new Runnable() {
            		
                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        String text = getPropertyByName(key);
                        TextView tv = (TextView) realView_;
                        if (!text.equalsIgnoreCase(tv.getText().toString())) {
                            tv.setText(text);
                            String tag = (String) tv.getTag();
                            if(com instanceof LPLabel || com instanceof LPHtmlText){
                            	reSetTextViewLayoutParams();
                            }
                        }
                    }
                });
            }
        } else if(key.equalsIgnoreCase("checked")){
        	boolean checked = false;
        	if(value != null && "true".equalsIgnoreCase(value)){ 
        		checked = true; // 获得选中状态。
        	}
        	// 支持更改checked属性的控件：checkbox。
        	if(this instanceof LPCheckBox){
        		property_.put("checked", value);
        		((MyLPCheckBox) realView_).setChecked(checked);
        	}
        }
    }

    /**
     * 获取默认的控件宽度值，如果后台未限制控件的宽度，控件的宽度有可能根据该值决定，该值取widget.xml中的对应控件的Frame_值
     * 
     * @return
     */
    protected int getAcquiescentWidth() {
        if (null == widgetType_)
            widgetType_ = "";
        if (null != WIDGETATTRIBUTES && null != WIDGETATTRIBUTES.get(getTag().concat(widgetType_))) {
            acquiescentWidth_ = Utils.getScaledValueX(Integer.parseInt((WIDGETATTRIBUTES.get(getTag().concat(
                    widgetType_).concat("w"))).toString()));
        } else {
            if (null == WIDGETATTRIBUTES)
                WIDGETATTRIBUTES = new HashMap<String, String>();
            if (null == attributes_)
                return acquiescentWidth_ = 0;
            String frame = attributes_.get("Frame_");
            String temp = frame;
            if (null != temp && temp.contains(",")) {
                temp = temp.substring(0, temp.lastIndexOf(","));
                if (temp.contains(",")) {
                    acquiescentWidth_ = Utils
                            .getScaledValueX(Integer.parseInt(temp.substring(temp.lastIndexOf(",") + 1)));
                    WIDGETATTRIBUTES.put(getTag().concat(widgetType_).concat("w"),
                            temp.substring(temp.lastIndexOf(",") + 1));
                }
            }
        }
        return acquiescentWidth_;
    }

    public void setProperty(HashMap hashmap) {
        property_ = hashmap;
    }

    public int getVisibility() {
        if (null != realView_) {
            if (getTag().equals("input") && getPropertyByName("type").equals("hidden")) {
                // LPHidden不是实体控件，但是需要提交该控件的相关属性，所以此处修改，主要是针对隐藏域控件
                return View.VISIBLE;
            } else {
                return realView_.getVisibility();
            }
        } else {
            return View.GONE;
        }

    }

    public LPLayout findForm() {
        // TODO Auto-generated method stub
        parent_ = (LPLayout) getParent();
        if (null == parent_)
            return null;
        if (null != parent_.getTag() && parent_.getTag().equalsIgnoreCase("form")) {
            return parent_;
        } else {
            // 否则向上递归
            parent_.findForm();
        }
        return null;
    }
    
    public LPLayout findparentForm(Component comp) {
        LPLayout ll = new LPLayout();
        Component currComp=comp.getParent();
        if (currComp.getTag() != null && currComp.getTag().equalsIgnoreCase("form")) {
            ll = (LPLayout) currComp;
            return ll;
        }else{
            return findparentForm(currComp);
            
        }
    }

    public static String encryptValue(String encryptMode, String value, WaitDialog.Task task) throws Exception {
        if (value == null || encryptMode == null) {
            return value;
        }
        if(RSACipherServerCer_ == null){
        	InputStream in = Utils.getActivity().getAssets().open(RSACipherServerCerfile_);
        	RSACipherServerCer_ = RSACipher.getCertificate(in);
        }
        String content = "";
        boolean needPasswordKey = false;
        if (encryptMode.equals("01")) {// 动态加密
        	content = Base64.encode(value.getBytes("UTF-8"));
            needPasswordKey = true;
        } else if (encryptMode.equals("A0")) {// APIN加密
        	byte[] endata = RSACipher.doEncrypt(value.getBytes("UTF-8"),
        		(RSAPublicKey) RSACipherServerCer_.getPublicKey(), RSACipher.TRANSFORMATION_RSA_ECB_PKCS1);
        	content = Base64.encode(endata);
        } else if (encryptMode.equals("A1")) {// APIN加密与动态加密
        	byte[] endata = RSACipher.doEncrypt(value.getBytes("UTF-8"),
        		(RSAPublicKey) RSACipherServerCer_.getPublicKey(), RSACipher.TRANSFORMATION_RSA_ECB_PKCS1);
        	content = Base64.encode(endata);
            needPasswordKey = true;
        }

        if (needPasswordKey && null == KEYTEMP && null == IVTEMP) {
            // ClientRandom
            byte[] cUnixTime = Utils.getClientGMTUnixTime();
            byte[] clientRandom = ClientHello.getClientRandom(28);
            byte[] RNC = new byte[32];
            System.arraycopy(cUnixTime, 0, RNC, 0, cUnixTime.length);
            System.arraycopy(clientRandom, 0, RNC, cUnixTime.length, clientRandom.length);
            String rncStr = Base64.encode(RNC);
            HttpManager hm = new HttpManager(Utils.getActivity());
            String body = "clientrandom=" + Utils.escapeURIComponent(rncStr);
            String enbody = body;
            enbody = AESCipher.encrypt(body, AESCipher.clientKey_, AESCipher.clientIv_);
            String status = (String) hm.sendPostRequest(
                    Utils.getConfigStringFormAsset(Utils.getActivity(), "SERVER_URI")
                            + Utils.getConfigStringFormAsset(Utils.getActivity(), "dynamickey"), enbody, task, null,
                    null);
            if (status == null)
                throw new NullPointerException(Constant.ERR_ENCRYPT_SERVER_01);
            if (status.indexOf("<error") != -1) {
                String error = Utils.getXMLResponseAttribute(status, "string=\"", 0, Utils.MATCH);
                if (HttpManager.isTimeout || HttpManager.isAppUpgrading)
                    return error;
                else
                    throw new Exception(error);
            }
            status = AESCipher.decrypt(status, AESCipher.serverKey_, AESCipher.serverIv_);
            String serverRandom = Utils.getXMLResponseAttribute(status, "serverrandom=\"", 0, Utils.MATCH);
            byte[] RNS = Base64.decodeToBytes(serverRandom);
            byte[] seed = new byte[RNC.length + RNS.length];
            System.arraycopy(RNC, 0, seed, 0, RNC.length);
            System.arraycopy(RNS, 0, seed, RNC.length, RNS.length);
            byte[] secret = HMac.PRF(ClientHello.PMS2_, HMac.TLS_ONCE_SECRET_CONST(), seed, 48);
            byte[] key = ClientHello.getAESKey(secret);
            byte[] iv = ClientHello.getAESIv(secret);
            KEYTEMP = key;
            IVTEMP = iv;
            byte[] data = null;
            data = AESCipher.encrypt(Base64.decodeToBytes(content), key, iv);
            content = Base64.encode(data);
        } else if (needPasswordKey && null != KEYTEMP && null != IVTEMP) {
            byte[] data = null;
            data = AESCipher.encrypt(Base64.decodeToBytes(content), KEYTEMP, IVTEMP);
            content = Base64.encode(data);
        }
        return content;
    }

    protected StringBuffer getBuffFromForm(Component comp, StringBuffer buf, String action, Task task) {
        // TODO Auto-generated method stub
        try {
            if (comp instanceof LPTextField) {
                LPTextField ltf = (LPTextField) comp;
                buf.append(ltf.getPropertyByName("name"));
                buf.append("=");
                String value = ltf.getContentText().trim();
                buf.append(Utils.escapeURIComponent(encryptValue((String) ltf.getPropertyByName("encryptMode"), value,
                        task)));
                buf.append("&");
            } else if (comp instanceof LPDateField) {
                LPDateField ltf = (LPDateField) comp;
                buf.append(ltf.attrName_);
                buf.append("=");
                String value = ltf.getContentText().trim();
                if (null == value || value.equals("")) {
                    buf.append(value);
                    buf.append("&");
                } else {
                    value = Utils.adjustDate(value);
                    buf.append(Utils.escapeURIComponent(encryptValue((String) ltf.getPropertyByName("encryptMode"),
                            value, task)));
                    buf.append("&");
                }
            } else if ((comp instanceof LPCheckBox && ((LPCheckBox) comp).isChecked())) {
                LPCheckBox lpcb = (LPCheckBox) comp;
                buf.append(lpcb.getPropertyByName("name"));
                buf.append("=");
                buf.append(Utils.escapeURIComponent(encryptValue((String) lpcb.getPropertyByName("encryptMode"),
                        lpcb.attrValue_, task)));
                buf.append("&");
            } else if ((comp instanceof LPRadio && ((LPRadio) comp).isChecked())) {

                LPRadio lpcb = (LPRadio) comp;
                buf.append(lpcb.getPropertyByName("name"));
                buf.append("=");
                buf.append(Utils.escapeURIComponent(encryptValue((String) lpcb.getPropertyByName("encryptMode"),
                        lpcb.attrValue_, task)));
                buf.append("&");
            } else if (comp instanceof LPSelect) {
                LPSelect lps = (LPSelect) comp;
                buf.append(lps.getPropertyByName("name"));
                buf.append("=");
                buf.append(Utils.escapeURIComponent(encryptValue((String) lps.getPropertyByName("encryptMode"),
                        lps.getContentText(), task)));
                buf.append("&");

            } else if (comp instanceof LPLabel) {
                LPLabel lplabel = (LPLabel) comp;
                buf.append(lplabel.getPropertyByName("name"));
                buf.append("=");
                buf.append(Utils.escapeURIComponent(encryptValue((String) lplabel.getPropertyByName("encryptMode"),
                		lplabel.getPropertyByName("value").trim(), task)));
                buf.append("&");
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            Utils.printException(e);
        }
        return buf;
    }

    public void setInnerHTML(final String str) {
        if(isShowLoading){
            LPToastUtil.getInstance().getToast( "数据加载中,请稍后...", getActivity());
        } else {
            parserComponent(str);
            // 如果包含，则说明是错误信息
            Activity activity = getActivity();
            activity.runOnUiThread(new Runnable() {

                public void run() {
                    // TODO Auto-generated method stub
                    Component.VWIDGETARRAY.remove(ComponentCopy.COMPONENTPARTLY);
                    //***只更新界面显示内容***
                    deleteChildComponent();
                    Component comp = addChildComponent(ComponentCopy.COMPONENTPARTLY);
                    //刷新界面布局
                    LPLayout temp = (LPLayout) comp.getParent();
                    if (null != comp && null != temp) {
                        comp.setComponentXYAgain();
                        temp.adjustTDWidth();
                        temp.checkChildLayoutInTR();
                        temp.checkChildLayout();
                    }
                }
            });
        }
    }
    
    int getStart() {
        return start_;
    }

    public void drawMoveStr(View view, Canvas g, int width, Paint font, String str, int x, int y) {
        int strWidth = (int) font.measureText(str);
        g.clipRect(x, y - font.getTextSize(), width, ((int) font.getTextSize()) << 1);
        // 当滚动字符串滚出横向半屏后，再从右侧滚出，所以当条件满足，应再画一次字符串
        g.drawText(str, x - getStart(), y, font);
        if (getStart() >= x + strWidth - (width >> 1) && str != null) {
            g.drawText(str, x - getStart() + strWidth + (width >> 1), y, font);
        }
        g.clipRect(x, 0, SCREENWIDTH, SCREENHEIGHT);
        // move 3 pels every step.
        // 该判断条件由-strWidth<= x-getStart() <=width决定
        if ((getStart() <= strWidth + x) && (getStart() > x - width))
            setStart(getStart() + 1);
        else
            setStart(x - (width >> 1));
        view.postInvalidate();
    }

    void setStart(int start) {
        start_ = start;
    }

    /**
     * 根据报文解析相应控件
     * 
     * @param str
     */
    private void parserComponent(String str) {
        // TODO Auto-generated method stub
        str = Utils.addXmlHead(str);
        str = Utils.unescapeHTML(str);
        str = Utils.insteadOfSpecillCharacter(str, true);
        AtomParser app = new AtomParser((Activity) realView_.getContext(), AtomParser.PARTLY);
        try {
            android.util.Xml.parse(str, app);
        } catch (SAXException e) {
            // TODO Auto-generated catch block
            Utils.printException(e);
        }
    }

    public int getLeft() {
        // TODO Auto-generated method stub
     	if(null == realView_){
    		return 0;
    	}
        return realView_.getLeft();
    }

    public int getWidth() {
        // TODO Auto-generated method stub
    	if(null == realView_){
    		return 0;
    	}
        return realView_.getWidth();
    }

    public int getTop() {
        // TODO Auto-generated method stub
     	if(null == realView_){
    		return 0;
    	}
        return realView_.getTop();
    }

    public int getHeight() {
        // TODO Auto-generated method stub
     	if(null == realView_){
    		return 0;
    	}
        return realView_.getHeight();
    }

    protected int getMeasuredHeight() {
        // TODO Auto-generated method stub
     	if(null == realView_){
    		return 0;
    	}
        return realView_.getMeasuredHeight();
    }

    protected int getMeasuredWidth() {
        // TODO Auto-generated method stub
     	if(null == realView_){
    		return 0;
    	}
        return realView_.getMeasuredWidth();
    }

    /**
     * 根据获取的宽高值重新定义xy值
     */
    public void adjustXY() {
        // TODO Auto-generated method stub
        try {
            LPLayout lpl = null;
            if (getParent() == null || !(getParent() instanceof LPLayout)) {
                return;
            } else {
                lpl = (LPLayout) getParent();
            }
            if (realView_.getVisibility() == View.GONE)
                return;

            android.widget.AbsoluteLayout.LayoutParams lp = (android.widget.AbsoluteLayout.LayoutParams) getLayoutParams();
            // 取得父控件的相关布局参数
            int left = Integer.MIN_VALUE;
            int top = Integer.MIN_VALUE;
            if (null != cssStyle_) {
                if (null != cssStyle_.getProperty(CssStyle.LEFT)) {
                    Object o = cssStyle_.getProperty(CssStyle.LEFT);
                    if (o instanceof String) {
                        left = Utils.getScaledValueX(Integer.parseInt(fixedPX((String) o)));
                    } else {
                        left = Utils.getScaledValueX((Integer) o);
                    }

                }

                if (null != cssStyle_.getProperty(CssStyle.TOP)) {
                    Object o = cssStyle_.getProperty(CssStyle.TOP);
                    if (o instanceof String) {
                        top = Utils.getScaledValueY(Integer.parseInt(fixedPX((String) o)));
                    } else {
                        top = Utils.getScaledValueX((Integer) o);
                    }

                }
            }
            int x = 0;
            int yTop = 0;
            if (!isAfterBr_ && ((lpl.xSelfMax_ + lp.width) > lpl.width_)) {
                // 修正br功能，自动排版。如果控件+布局超过父控件宽度
                // 则修改br标志
//                isAfterBr_ = true;
            }
            if (left != Integer.MIN_VALUE) {
                // 服务端已经规定了控件的x值
                x = left;
            } else {
                if (isAfterBr_) {
                    x = 0;
                } else {
                    x = lpl.xSelfMax_;   
                }
                if (0 != x) {
                    // 表示该控件不是每排的第一个控件且报文未给他指定x值
                    // 此时我们应给控件累加一个默认的控件间距
                    x = x + lpl.getHG();
                }
            }

            if (top != Integer.MIN_VALUE) {
                yTop = top;
                /**
                 * 纠正llv结构其直系子元素的高度。由于android与iphone在结构上的差异，android产品为了更好的实现滚动效果
                 * 在界面上人为的插入了一层llv，所以应对xml结构中的llv子元素的top作相应的调整
                 */
                String tag = lpl.getTag();
                if (tag.equalsIgnoreCase("llv")) {
                    // 表示该控件为llv层的直系子元素
                    if (lpl.llvTop_ == 0) {
                        // 计算llv里面直接子元素应该让度的top值
                        lpl.llvTop_ = lpl.getLLVTop();
                    }

                    yTop = yTop - lpl.llvTop_;
                }
                lpl.setYTop(yTop);
            } else {
                if (isAfterBr_) {
                    yTop = lpl.ySelfMax_ + brHeight_;
                    lpl.setYTop(yTop);
                } else {
                    yTop = lpl.ySelfTop_;
                }
                if (0 != lpl.ySelfTop_) {
                    // 表示该控件不是出于框架的第一排，且报文未给他指定ｙ值
                    // 此时我们应给控件累加一个默认的控件间距
                    yTop = yTop + lpl.getVG();
                } else {
                    // 如果不指定高度,且位于第一排,则应给与高度值
                    yTop = yTop + lpl.getVM();
                }
            }

            // 重新设置自身的布局参数
            left_ = x;
            top_ = yTop;
            lp.x = left_;
            lp.y = top_;
            setLayoutParams(lp);

            yParentTop_ = yTop;
            // 更新父控件的相关布局参数，为后面控件布局指定作准备
            lpl.setXMax((x == 0) ? lp.width : (x + lp.width));
            // 记录控件相对于父控件的X布局值
            xParentMax_ = lpl.xSelfMax_;

            lpl.setYMax(Math.max(yTop + lp.height, lpl.ySelfMax_));
            // 记录控件相对于父件的YY布局值
            yParentMax_ = lpl.ySelfMax_;
            lpl.setHMax(Math.max(lpl.hSelfMax_, lpl.ySelfMax_ + lpl.getVM()));
            hParentMax_ = lpl.hSelfMax_;
            lpl.setWMax(Math.max(lpl.wSelfMax_, lpl.xSelfMax_));
            wParentMax_ = lpl.wSelfMax_;
        } catch (Exception e) {
            Utils.printException(e);
        }
    }

    /**
     * 在控件外面加一个scrollview，并且设置其高度
     * 
     * @param height
     *            scrollview控件对应的高度值
     */
    protected void addSCasParent(int height) {
        ScrollView scrollView = new ScrollView(getContext());
        ViewGroup vg = (ViewGroup) realView_.getParent();
        LayoutParams lParams = new android.widget.AbsoluteLayout.LayoutParams(AbsoluteLayout.LayoutParams.WRAP_CONTENT,
                height, 0, 0);
        scrollView.setLayoutParams(lParams);
        if (null != vg) {
            vg.addView(scrollView, vg.indexOfChild(realView_));
            vg.removeView(realView_);
            scrollView.addView(realView_);
            if (!getTag().equalsIgnoreCase("llv")) {
                // 如果当前控件不是llv层，则都须对scrollview做出限制，防止上层scrollview截获滑动事件
                scrollView.getParent().requestDisallowInterceptTouchEvent(true);
            }
        }

        if (!getTag().equalsIgnoreCase("llv")) {

            scrollView.setOnTouchListener(new View.OnTouchListener() {
                View view;
                Component c;
                String nexturl;
                ViewParent vp;

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    // TODO Auto-generated method stub
                    switch (event.getAction()) {
                    case MotionEvent.ACTION_MOVE:
                        view = ((ScrollView) v).getChildAt(0);
                        c = getComponent(view);
                        if (v.getScrollY() == (view.getMeasuredHeight() - v.getHeight())) {
                            nexturl = ((String) c.getPropertyByName("nextUrl")).trim();
                            if (!nexturl.equals("")) {
                                if (nexturl.startsWith("lp")) {
                                    nexturl = "http".concat(nexturl.substring(2, nexturl.length()));
                                    throwPage(c, nexturl);
                                }
                            }
                        }
                        break;
                    default:
                        break;
                    }
                    return false;
                }

            });
        }
    }

    protected ViewParent getScrollView(View v) {
        // TODO Auto-generated method stub
        ViewParent vp = v.getParent();
        if (vp instanceof ScrollView) {
            return vp;
        } else {
            return getScrollView((View) vp);
        }
    }

    /**
     * 拖拽翻页操作，主要表现在表格控件添加数据
     * 
     * @param c
     *            执行拖拽翻页将新数据加载至的控件
     * @param nexturl
     *            获取数据的地址
     */
    protected void throwPage(Component c, final String url) {
        // TODO Auto-generated method stub
        final HttpManager hm = new HttpManager(getActivity());
        Thread thread = new Thread(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                String replay;
                String urltemp = Utils.getConfigStringFormAsset(getActivity(), "SERVER_URI");
                if (!url.startsWith("http"))
                    urltemp = urltemp.concat(url);
                else
                    urltemp = url;
                try {
                    replay = (String) hm.sendHttpRequest(urltemp, null, HttpManager.GET, null, null);
                    replay = AESCipher.decrypt(replay, AESCipher.serverKey_, AESCipher.serverIv_);
                    replay = Utils.unescapeHTML(replay);
                    replay = Utils.insteadOfSpecillCharacter(replay, true);
                    Utils.printOutToConsole(replay);
                    AtomParser app = new AtomParser(getActivity(), AtomParser.PARTLY);
                    android.util.Xml.parse(replay, app);

                    getActivity().runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            // 通过以上解析，得到控件封装在ComponentCopy.COMPONENTPARTLY内
                            Component temp;
                            if (ComponentCopy.COMPONENTPARTLY instanceof LPLayout) {
                                List list = new ArrayList<Component>(2);
                                LPLayout layout = (LPLayout) ComponentCopy.COMPONENTPARTLY;
                                setPropertyByName("nextUrl", layout.getPropertyByName("nextUrl"));
                                int size = layout.getChildCount();
                                for (int i = 0; i < size; i++) {
                                    temp = null;
                                    temp = layout.getChildAt(i);
                                    list.add(temp);
                                }
                                layout.removeAllViews();
                                if (getTag().equalsIgnoreCase("table") && getPropertyByName("nextUrl").equals("")

                                && getChildAt(getChildCount() - 1).getTag().equalsIgnoreCase("loading")) {

                                    // 如果没有nextUrl标记，则检查table控件内是否有loading显示域控件，如果有，将其清除

                                    removeView(getChildAt(getChildCount() - 1));

                                }
                                size = list.size();
                                for (int i = 0; i < size; i++) {
                                    addView((Component) list.get(i));
                                }
                                ComponentCopy.COMPONENTPARTLY = null;
                            } else {
                                addView(ComponentCopy.COMPONENTPARTLY);
                            }

                            // 重新布局结构里面所有的子元素
                            hSelfMax_ = 0;
                            xSelfMax_ = 0;
                            ySelfMax_ = 0;
                            ySelfTop_ = 0;
                            final int sizeNow = getChildCount();
                            for (int i = 0; i < sizeNow; i++) {
                                temp = (Component) getChildAt(i);
                                temp.mouldAndLayout();
                            }
                            throwPageIsWork_ = false;
                        }

                    });

                } catch (NoGatewayException e) {
                    // TODO Auto-generated catch block
                    Utils.printException(e);
                    throwPageIsWork_ = false;
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    Utils.printException(e);
                    throwPageIsWork_ = false;
                }
            }
        });
        thread.start();
    }

    public int getChildCount() {
        return 0;
    }

    /**
     * 通过lua方式获取子控件lua table
     * 
     * @return
     */
    public LuaObject getChildren() {
        int size = childrenList_.size();
        Component child;
        // 创建一个table
        LUASTATE.newTable();
        LuaObject tableTemp = Component.LUASTATE.getLuaObject(-1);
        try{
            for (int i = 0; i < size; i++) {
                child = childrenList_.get(i);
                //如果直接使用i，最终数据少一条
                Component.LUASTATE.pushObjectValue(i + 1);
                Component.LUASTATE.pushObjectValue(child);
                Component.LUASTATE.setTable(-3);
            }
        } catch (LuaException e) {
            // TODO Auto-generated catch block
            Utils.printException(e);
        }
        return tableTemp;
    }

    public Component getChildAt(int i) {
        return null;
    }

    public String getContentText() {
        // TODO Auto-generated method stub
        if (realView_ instanceof TextView) {
            TextView tv = (TextView) realView_;
            return (String) tv.getText();
        }
        return "";
    }

    /**
     * 展示加载动画。（每个控件都可调用）
     */
    public void showLoading() {
        try {
            LPLoadingView sl = new LPLoadingView();
            sl.initRealView(getActivity(), "" , false);
            LayoutParams lp = getLayoutParams();
            // 给loading控件打上标，表示是由该控件衍生所出
            sl.setTag(getTag().concat(getPropertyByName("name")).concat("showLoading"));
            if (null != lp) {
                sl.setLayoutParams(lp);
                sl.width_ = lp.width;
                sl.height_ = lp.height;
                sl.mouldH();
            }
            parentComponent_ = getParent();
            parentComponent_.addView(sl);
            isShowLoading = true;
        } catch (Exception e) {
            // TODO Auto-generated catch block
            Utils.printException(e);
        }
    }

    /**
     * 停止加载动画。（每个控件都可调用）
     */
    public void stopLoading() {
        parentComponent_ = getParent();
        int size = parentComponent_.getChildCount();
        Component tempComponent;
        String tempTag;
        for (int i = 0; i < size; i++) {
            tempComponent = parentComponent_.getChildAt(i);
            tempTag = tempComponent.getTag();
            if (null != tempComponent && null != tempTag
                    && tempTag.equals(getTag().concat(getPropertyByName("name")).concat("showLoading"))) {
                // 检测是否是对应的loading界面
                tempComponent.disinheritance();
                tempComponent.releaseResource(tempComponent);
                isShowLoading = false;
            }
        }
    }

    public void setLPTag(String tag) {
        lpTag_ = tag;
    }

    public String getLPTag() {
        return lpTag_;
    }

    /**
     * 返回控件依附的界面参数
     * 
     * @return
     */
    public Activity getActivity() {
        if (null != realView_)
            return (Activity) realView_.getContext();
        return null;
    }

    /**
     * 遍历执行控件的mould方法和布局方法
     */
    public void mouldAndLayout() {
        // TODO Auto-generated method stub
        try {
            // 先横向排版确定宽度，再便利子元素纵向排版
            mouldW();
            if (this instanceof LPLayout) {
                String tag = getTag();
                hSelfMax_ = 0;
                xSelfMax_ = 0;
                ySelfMax_ = 0;
                ySelfTop_ = 0;
                Component c = null;
                Component cp = null;
                if (null != childrenList_) {
                    int size = childrenList_.size();
                    for (int i = 0; i < size; i++) {
                        c = childrenList_.get(i);
                        cp = c.getParent();
                        /* 如果控件还存在父控件先将其从父控件上移除 */
                        if (cp != null) {
                            cp.removeView(c);
                        }
                        addView(c);
                        c.mouldAndLayout();
                    }
                }
            }
            mouldH();
            adjustXY();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            Utils.printException(e);
        }
    }

    /**
     * 设置父系节点控件，在读取xml时候确定字节点的父系节点控件
     * 
     * @param component
     *            控件的父系节点控件
     */
    public void setParent(Component component) {
        // TODO Auto-generated method stub
        parentComponent_ = component;
    }

    /**
     * 遍历childrenList_集合让child执行mould方法
     */
    public void mouldChildList() {
        Component c = null;
        if (null != childrenList_ && childrenList_.size() > 0) {
            int size = childrenList_.size();
            for (int i = 0; i < size; i++) {
                c = childrenList_.get(i);
                try {
                    c.mouldW();
                    c.mouldH();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /**
     * 设置控件内容对齐格式
     * 
     * @param gravity
     */
    public void setGravity(int gravity) {
        // TODO Auto-generated method stub
        if (null != realView_ && realView_ instanceof TextView) {
            TextView tv = (TextView) realView_;
            tv.setGravity(gravity);
        }
    }
    
    /**
     * 获取矩阵
     * */
    public LuaObject getMatrix() {
        LuaObject object = null;
        
        try{
            Component.LUASTATE.newTable();//创建一个table
            object = Component.LUASTATE.getLuaObject(-1);
            
            Component.LUASTATE.pushObjectValue("m11");
            Component.LUASTATE.pushObjectValue(String.valueOf(matrixValues_[0]));
            Component.LUASTATE.setTable(-3);
            Component.LUASTATE.pushObjectValue("m12");
            Component.LUASTATE.pushObjectValue(String.valueOf(matrixValues_[1]));
            Component.LUASTATE.setTable(-3);
            Component.LUASTATE.pushObjectValue("m13");
            Component.LUASTATE.pushObjectValue(String.valueOf(matrixValues_[2]));
            Component.LUASTATE.setTable(-3);
            
            Component.LUASTATE.pushObjectValue("m21");
            Component.LUASTATE.pushObjectValue(String.valueOf(matrixValues_[3]));
            Component.LUASTATE.setTable(-3);
            Component.LUASTATE.pushObjectValue("m22");
            Component.LUASTATE.pushObjectValue(String.valueOf(matrixValues_[4]));
            Component.LUASTATE.setTable(-3);
            Component.LUASTATE.pushObjectValue("m23");
            Component.LUASTATE.pushObjectValue(String.valueOf(matrixValues_[5]));
            Component.LUASTATE.setTable(-3);
            
            Component.LUASTATE.pushObjectValue("m31");
            Component.LUASTATE.pushObjectValue(String.valueOf(matrixValues_[6]));
            Component.LUASTATE.setTable(-3);
            Component.LUASTATE.pushObjectValue("m32");
            Component.LUASTATE.pushObjectValue(String.valueOf(matrixValues_[7]));
            Component.LUASTATE.setTable(-3);
            Component.LUASTATE.pushObjectValue("m33");
            Component.LUASTATE.pushObjectValue(String.valueOf(matrixValues_[8]));
            Component.LUASTATE.setTable(-3);
        }catch(LuaException e){
            Utils.printException(e);
        }
        return object;
    }
    
    /**
     * 设置矩阵
     * */
    public void setMatrix(LuaObject table){
        Map<String,Integer> map = Utils.getMatrixIndex();
        Map changePoint = Utils.getTableValue(table);
        
        Iterator it = changePoint.keySet().iterator();
        while(it.hasNext()){
            String key = (String)it.next();
            if(map.containsKey(key)){
                matrixValues_[map.get(key)] = Float.valueOf((String) changePoint.get(key));
            }
        }
        
        float[] fromMatrix = new float[]{1f,0f,0f,0f,1f,0f,0f,0f,1f};
        float[] toMatrix = new float[]{1f,0f,0f,0f,1f,0f,0f,0f,1f};
                 
        Iterator itTo= changePoint.keySet().iterator();
        while(itTo.hasNext()){
            String key = (String)itTo.next();
            if(map.containsKey(key)){
                toMatrix[map.get(key)] = Float.valueOf((String) changePoint.get(key));
            }
        }
        
        EmpAnimation eaAnimation = new EmpAnimation();
        eaAnimation.setMatrix(fromMatrix , toMatrix ,width_ / 2 ,height_ / 2 );
        eaAnimation.setDuration(100);
        eaAnimation.setFillAfter(true);
        startAnimation(eaAnimation);
    }
    
    /**
     * 按下控件导致tr变色的方法。
     * 
     * @param tr_ 当前控件所在的tr。
     * @param llvSV_ 当前控件所在的滚动视图。
     */
    public void trDownColor(Component tr_, Component llvSV_){
    	if(tr_ != null){
            if(tr_.cssStyle() == null){
            	tr_.setCssStyle(new CssStyle());
            }
            ((MyLPLayout)tr_.realView_).isSpecialTRBg_ = true;
            tr_.cssStyle().setProperty(CssStyle.BACKGROUNDCOLOR, Utils.TR_CHANGE_BG_);
            tr_.realView_.invalidate();
            if(llvSV_ == null){
            	llvSV_ = Utils.sc_;
            }
            if(llvSV_ != null){
            	((LPScrollView) llvSV_).currentTR_ = tr_;
            }
            if(hs_ != null){
            	hs_.currentTR_ = tr_;
            }
            if(vs_ != null){
            	vs_.currentTR_ = tr_;
            }
        }
    }
    
    /**
     * 移动控件导致tr恢复颜色的方法。
     * 
     * @param tr_ 当前控件所在的tr。
     * @param llvSV_ 当前控件所在的滚动视图。
     */
    public void trMoveColor(Component tr_, Component llvSV_){
    	if(tr_ != null){
			tr_.setCssStyle(((LPLayout) tr_).oldTRCssStyle_);
			((MyLPLayout)tr_.realView_).isSpecialTRBg_ = ((LPLayout) tr_).oldSpecialTR_;
			tr_.realView_.invalidate();
			if(llvSV_ != null){
    			((LPScrollView) llvSV_).currentTR_ = null;
    		}
			if(hs_ != null){
				hs_.currentTR_ = null;
			}
			if(vs_ != null){
				vs_.currentTR_ = null;
			}
		}
    }
    
    /**
     * 抬起控件导致tr恢复颜色的方法。
     * 
     * @param tr_ 当前控件所在的tr。
     * @param llvSV_ 当前控件所在的滚动视图。
     */
    public void trUpColor(Component tr_, Component llvSV_){
    	if(tr_ != null){
            tr_.setCssStyle(((LPLayout) tr_).oldTRCssStyle_);
        	((MyLPLayout)tr_.realView_).isSpecialTRBg_ = ((LPLayout) tr_).oldSpecialTR_;
            tr_.realView_.invalidate();
            if(llvSV_ != null){
            	((LPScrollView) llvSV_).currentTR_ = null;
            }
            if(hs_ != null){
            	hs_.currentTR_ = null;
            }
            if(vs_ != null){
            	vs_.currentTR_ = null;
            }
        }
    }
    
    /**
     * 登记当前控件所处的横向滚动视图的方法。
     * 
     * @param source 当前控件。
     * @param hs source控件所处的横向滚动视图。
     */
    public void regHS(Component source, HSView hs){
    	if(source != null && hs != null){
    		source.hs_ = hs;
    		// 如果source是个容器类的视图，比如table，那么其中的子view也是需要登记的，这里用了一个递归方法。
    		if(source instanceof LPLayout){
    			int childSize = ((LPLayout) source).getCompChildCount();
    			if(childSize > 0){
    				for (int i = 0; i < childSize; i++) {
						source.regHS(((LPLayout) source).getCompChildAt(i), hs);
					}
    			}
    		}
    	}
    }
    
    /**
     * 登记当前控件所处的纵向滚动视图的方法。
     * 
     * @param source 当前控件。
     * @param vs source控件所处的纵向滚动视图。
     */
    public void regVS(Component source, LPScrollView vs){
    	if(source != null && vs != null){
    		source.vs_ = vs;
    		// 如果source是个容器类的视图，比如table，那么其中的子view也是需要登记的，这里用了一个递归方法。
    		if(source instanceof LPLayout){
    			int childSize = ((LPLayout) source).getCompChildCount();
    			if(childSize > 0){
    				for (int i = 0; i < childSize; i++) {
						source.regVS(((LPLayout) source).getCompChildAt(i), vs);
					}
    			}
    		}
    	}
    }
    
    /**
     * 获得按钮不同状态下的图片。
     */
    public void getButtonStatusBG(){
    	if(cssStyle_ != null && cssStyle_.getProperty(CssStyle.BGIMAGEURL) != null){
        	String upBGString = cssStyle_.getProperty(CssStyle.BGIMAGEURL);
        	// 去.png后缀。
        	upBGString = upBGString.endsWith(".png") ?
        			upBGString.substring(0, upBGString.lastIndexOf(".png")) : upBGString;
        	upBG_ = Utils.getResourcesId(getContext(), upBGString, "drawable");
        }
        String focusBgImageUrl = getPropertyByName("highlightbg");
        if(focusBgImageUrl != null && !"".equals(focusBgImageUrl)){
        	// 去local前缀。
        	focusBgImageUrl = focusBgImageUrl.contains("local:") ?
        			focusBgImageUrl.substring(focusBgImageUrl.indexOf("local:") + 6).trim() : focusBgImageUrl;
        	// 去.png后缀。
        	focusBgImageUrl = focusBgImageUrl.endsWith(".png") ? 
        			focusBgImageUrl.substring(0, focusBgImageUrl.lastIndexOf(".png")) : focusBgImageUrl;
        	downBG_ = Utils.getResourcesId(getContext(), focusBgImageUrl, "drawable");
        }
    }
}
